Problem description
When using the su command to switch users, you receive the following error:
su: failed to execute /bin/bash: Permission deniedCause
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
Log on to the ECS instance.
Go to ECS console - Instance. In the top navigation bar, select the target region and resource group.
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.
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.
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/bashIf the output includes an
ioraflag, remove it in the next step. Otherwise, proceed to Step 3.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/bashAfter removing the attributes, continue to the next step.
Verify and correct path permissions.
Check the full permission path.
sudo namei -l /bin/bashf: /bin/bash dr-xr-xr-x root root / dr-xr-xr-x root root bin -r-xr-xr-x root root bashEach 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 (
/) weredr--r--r--, it would indicate a missing execute permission that you must fix.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
Verify the fix.
Run the
sucommand again to switch to the target user. The error should now be resolved.