All Products
Search
Document Center

:Resolve the "su: failed to execute /bin/bash: Permission denied" error on a Linux instance

Last Updated:Nov 11, 2025

Problem description

When using the su command to switch users, you receive the following error:

su: failed to execute /bin/bash: Permission denied

Cause

This error indicates insufficient permissions on the path to /bin/bash. Specifically, the file or a parent directory is missing the execute (x) permission. Without this permission, the system cannot access the /bin/bash executable to start a new shell session.

Solution

  1. Log on to the ECS instance.

    1. Go to ECS console - Instance. In the top navigation bar, select the target region and resource group.

    2. Go to the details page of the target instance. Click Connect and select Workbench. Follow the prompts on the page to log on to the terminal.

  2. Check for and remove immutable attributes.

    If a file has an immutable or append-only attribute, you cannot modify its permissions until you remove the attribute.

    1. Check for immutable attributes.

      sudo lsattr /bin/bash
      # Indicates the 'a' (append-only) attribute is set
      ----a---------e------ /bin/bash
      # Indicates the 'i' (immutable) attribute is set
      ----i---------e------ /bin/bash
      # Indicates both attributes are set
      ----ia--------e------ /bin/bash

      If the output includes an i or a flag, remove it in the next step. Otherwise, proceed to Step 3.

    2. Remove the attributes.

      # Run this command if the 'i' attribute is set
      sudo chattr -i /bin/bash
      # Run this command if the 'a' attribute is set
      sudo chattr -a /bin/bash

      After removing the attributes, continue to the next step.

  3. Verify and correct path permissions.

    1. Check the full permission path.

      sudo namei -l /bin/bash
      f: /bin/bash
      dr-xr-xr-x root root /
      dr-xr-xr-x root root bin
      -r-xr-xr-x root root bash

      Each directory in the path must have execute (x) permission. If your output shows that a permission is missing, you must correct it. Otherwise, proceed to Step 4.

      For example, if the permissions for the root directory (/) were dr--r--r--, it would indicate a missing execute permission that you must fix.
    2. Apply the correct permissions using chmod.

      # Correct permissions for the root directory (/)
      sudo chmod 755 /
      
      # Correct permissions for the /bin directory
      sudo chmod 755 /bin
      
      # Correct permissions for the /bin/bash file
      sudo chmod 755 /bin/bash
  4. Verify the fix.

    Run the su command again to switch to the target user. The error should now be resolved.