"Permission denied" when accessing /tmp on a Linux instance
Problem
Running cd /tmp on a CentOS 7 instance returns this error:
bash: cd: /tmp: Permission denied
Cause
The /tmp directory has incorrect permissions. By default, /tmp uses mode 1777 (sticky bit, world-readable/writable/executable). If changed, non-root users cannot access it.
Common causes include:
-
A
chmodcommand ran on/tmpwithout preserving the sticky bit -
A script or configuration management tool reset the permissions
-
Security hardening inadvertently restricted access to
/tmp
Solution
Alibaba Cloud reminds you that:
- Before you modify instance configurations or data, check the disaster recovery and fault tolerance capabilities of your instances to ensure data security.
- You can modify the configurations and data of instances including but not limited to ECS and 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 your logon account and password in the Alibaba Cloud Management Console, we recommend that you change this information promptly.
As the root user, restore the correct permissions:
chmod 1777 /tmp
Verify the permissions:
ls -ld /tmp
Sample output:
drwxrwxrwt 2 root root 4096 Feb 17 10:00 /tmp
The trailing t confirms the sticky bit is set. The inode count, file size, and timestamp 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 can delete or rename files owned by others.
Applicable products
-
Elastic Compute Service (ECS)
-
Simple Application Server