Problem
Running cd /tmp on a CentOS 7 instance returns the following error:
bash: cd: /tmp: Permission deniedCause
The /tmp directory has incorrect permissions. By default, /tmp uses permission mode 1777 (sticky bit set, world-readable/writable/executable). If these permissions are changed, non-root users cannot access the directory.
Common causes:
A
chmodcommand was run on/tmpwithout preserving the sticky bitA script or configuration management tool reset the directory permissions
Security hardening inadvertently restricted
/tmpaccess
Solution
Alibaba Cloud reminds you that:
- Before you perform operations that may cause risks, such as modifying instance configurations or data, we recommend that you check the disaster recovery and fault tolerance capabilities of the instances to ensure data security.
- You can modify the configurations and data of instances including but not limited to Elastic Compute Service (ECS) and Relational Database Service (RDS) instances. Before the modification, we recommend that you create snapshots or enable RDS log backup.
- If you have authorized or submitted sensitive information such as the logon account and password in the Alibaba Cloud Management Console, we recommend that you modify such information in a timely manner.
Run the following command as the root user to restore the correct permissions:
chmod 1777 /tmpVerify that the permissions are correct:
ls -ld /tmpExpected output:
drwxrwxrwt 2 root root 4096 Feb 17 10:00 /tmpThe t at the end of the permission string confirms that the sticky bit is set. The inode count, file size, and timestamp in the output vary by instance.
Permission breakdown
| Digit | Value | Meaning |
|---|---|---|
1 | Sticky bit | Prevents users from deleting files owned by others |
7 | Owner (root) | Read + write + execute |
7 | Group (root) | Read + write + execute |
7 | Others | Read + write + execute |
The sticky bit is critical for shared directories like /tmp. Without it, any user could delete or rename files owned by other users.
Applicable products
Elastic Compute Service (ECS)
Simple Application Server