EasyDebug.NET

File Permissions Reference

Digits and symbols both ways, special bits, umask, and the commands to apply them

rwxr-xr-x

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 bits

r--

Read only; the usual mode for read-only files and keys.

5Permission bits

r-x

Read and execute, the classic mode for scripts and binaries.

6Permission bits

rw-

Read and write, the classic mode for data files.

7Permission bits

rwx

Full permission; a directory needs this to be entered.

rwxPermission bits

7

Letters to digits: r=4, w=2, x=1, summed per triad.

-Permission bits

0

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 modes

r--------

Owner read only; required for private keys.

440Common modes

r--r-----

Owner and group can read.

444Common modes

r--r--r--

Readable by everyone; common for cron files.

600Common modes

rw-------

Owner read-write only, for configs holding secrets.

640Common modes

rw-r-----

Owner read-write, group read.

644Common modes

rw-r--r--

The default for regular files.

660Common modes

rw-rw----

Owner and group read-write.

664Common modes

rw-rw-r--

Group writable; common in shared directories.

666Common modes

rw-rw-rw-

Read-write for everyone; usually a mistake.

700Common modes

rwx------

Owner-only access; private directories.

750Common modes

rwxr-x---

Owner full, group read and traverse.

755Common modes

rwxr-xr-x

The default for directories and scripts.

775Common modes

rwxrwxr-x

Group-writable directory for team shares.

777Common modes

rwxrwxrwx

Full access for everyone; never on production web roots.

555Common modes

r-xr-xr-x

Read-only directory; prevents deletion but also writes.

500Common modes

r-x------

Owner-only executable.

111Common modes

--x--x--x

Executable by all but readable by none; rare and hard to debug.

drwxr-xr-xCommon modes

chmod 755 dir

On a directory the x bit allows entering; r alone only lists names.

644 / 755Common modes

644 文件 / 755 目录

Files 644, directories and scripts 755: the general default.

chown -R www-data:www-dataCommon modes

chown -R www-data:www-data dir

Give ownership to the service account instead of opening permissions.

4Special bits

setuid

setuid: run as the file owner; a risky bit.

2Special bits

setgid

setgid: run as the file group; on directories, new files inherit the group.

1Special bits

sticky

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 bits

rwxrwsr-x

setgid directory: the standard for team shares.

1777Special bits

rwxrwxrwt

sticky plus 777; /tmp uses exactly this.

chmod u+s fileSpecial bits

4755

Add setuid to a file.

chmod g+s dirSpecial bits

2775

Add setgid to a directory so new files inherit its group.

chmod +t dirSpecial bits

1777

Add the sticky bit.

rwSr--r--Special bits

rwSr--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 -Sumask

u=rwx,g=rx,o=rx

Show the mask symbolically, easier to read.

666 - umaskumask

666 与 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 bCommands

b 复制 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" fileCommands

644 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
Author's Blog
Share an idea