File Permissions Reference
Digits and symbols both ways, special bits, umask, and the commands to apply them
65 entries
0Permission bits---
No permission at all.
1Permission bits--x
Execute only; the file runs but cannot be read.
2Permission bits-w-
Write only; rarely useful in practice.
3Permission bits-wx
Write and execute.
4Permission bitsr--
Read only; the usual mode for read-only files and keys.
5Permission bitsr-x
Read and execute, the classic mode for scripts and binaries.
6Permission bitsrw-
Read and write, the classic mode for data files.
7Permission bitsrwx
Full permission; a directory needs this to be entered.
rwxPermission bits7
Letters to digits: r=4, w=2, x=1, summed per triad.
-Permission bits0
Placeholder shown when a permission bit is off.
dPermission bits-
Type bit: d for directory, dash for regular file, l for symlink.
-rw-r--r--Permission bits第 2 位 = 同组
Read permissions as three triads: owner, group, others.
400Common modesr--------
Owner read only; required for private keys.
440Common modesr--r-----
Owner and group can read.
444Common modesr--r--r--
Readable by everyone; common for cron files.
600Common modesrw-------
Owner read-write only, for configs holding secrets.
640Common modesrw-r-----
Owner read-write, group read.
644Common modesrw-r--r--
The default for regular files.
660Common modesrw-rw----
Owner and group read-write.
664Common modesrw-rw-r--
Group writable; common in shared directories.
666Common modesrw-rw-rw-
Read-write for everyone; usually a mistake.
700Common modesrwx------
Owner-only access; private directories.
750Common modesrwxr-x---
Owner full, group read and traverse.
755Common modesrwxr-xr-x
The default for directories and scripts.
775Common modesrwxrwxr-x
Group-writable directory for team shares.
777Common modesrwxrwxrwx
Full access for everyone; never on production web roots.
555Common modesr-xr-xr-x
Read-only directory; prevents deletion but also writes.
500Common modesr-x------
Owner-only executable.
111Common modes--x--x--x
Executable by all but readable by none; rare and hard to debug.
drwxr-xr-xCommon modeschmod 755 dir
On a directory the x bit allows entering; r alone only lists names.
644 / 755Common modes644 文件 / 755 目录
Files 644, directories and scripts 755: the general default.
chown -R www-data:www-dataCommon modeschown -R www-data:www-data dir
Give ownership to the service account instead of opening permissions.
4Special bitssetuid
setuid: run as the file owner; a risky bit.
2Special bitssetgid
setgid: run as the file group; on directories, new files inherit the group.
1Special bitssticky
sticky: only the owner may delete files in the directory; this is what /tmp uses.
4755Special bits-rwsr-xr-x
setuid plus 755, common for binaries that need elevation.
2755Special bits-rwxr-sr-x
setgid plus 755.
2775Special bitsrwxrwsr-x
setgid directory: the standard for team shares.
1777Special bitsrwxrwxrwt
sticky plus 777; /tmp uses exactly this.
chmod u+s fileSpecial bits4755
Add setuid to a file.
chmod g+s dirSpecial bits2775
Add setgid to a directory so new files inherit its group.
chmod +t dirSpecial bits1777
Add the sticky bit.
rwSr--r--Special bitsrwSr--r--
Lowercase s means the x bit is set; uppercase S means it is not, so it does nothing.
022umask文件 644 / 目录 755
The default mask: removes group and other write from 666 and 777.
002umask文件 664 / 目录 775
Allows group write; common on shared machines.
027umask文件 640 / 目录 750
Denies others entirely; stricter servers.
077umask文件 600 / 目录 700
Strictest: only you can touch new files and directories.
umaskumask当前掩码
Show the current mask; it can differ per shell.
umask -Sumasku=rwx,g=rx,o=rx
Show the mask symbolically, easier to read.
666 - umaskumask666 与 022 得到 644
New files start from 666 minus the mask; directories from 777.
umask 022umask仅当前 shell 生效
The mask lasts only for the current session; make it persistent in shell config.
chmod 755 fileCommands数字改权限
The usual way to set permissions.
chmod u+x fileCommands给所有者加执行位
Symbolic form: change one bit and leave the rest.
chmod -R 755 dirCommands递归改目录内全部
Recursive change also hits files; usually not what you want.
chmod --reference=a bCommandsb 复制 a 的权限
Copy the mode from another file instead of computing it.
chown user:group fileCommands同时改所有者与组
Change owner and group together.
chown -R www-data:www-data /var/wwwCommands递归改归属
Hand the web root to the service account; far better than 777.
chgrp group fileCommands只改所属组
Change only the group.
ls -lCommands-rw-r--r-- 1 ada dev
Read the first column: type bit plus three triads.
stat -c "%a %n" fileCommands644 file
Print the numeric mode; far more reliable than parsing ls.
find . -type f -exec chmod 644 {} \;Commands只改文件
Set modes per type; the standard fix for a 777 accident.
find . -type d -exec chmod 755 {} \;Commands只改目录
Pair it with the previous command.
getfacl fileCommands查看 ACL
Inspect ACLs beyond the standard permission bits.
setfacl -m u:user:rw fileCommands给指定用户授权
Grant via ACL without changing groups.
sudo -u user cmdCommands以指定用户身份执行
Run a command as another user, useful for permission debugging.
Something broken or missing?
Send feedback