Chmod calculator

Tick permissions to get the chmod number and symbolic notation, or type a number to decode it.

Owner
Group
Others
Symbolic
Command

This tool runs in your browser. We never send what you type or paste to a server.

How the numbers work

Each digit is the sum of read (4), write (2) and execute (1) for one group: the owner, the group and everyone else. So 7 = 4 + 2 + 1 (rwx), 5 = 4 + 1 (r-x) and 4 = read only.

  • 755 (rwxr-xr-x): programs and folders. Owner can change; everyone can read and run.
  • 644 (rw-r--r--): normal files. Owner can edit; everyone can read.
  • 600 (rw-------): private files such as SSH keys.
  • 777: anyone can change it. Almost never the right answer on a server.

Common values

755   rwxr-xr-x   scripts and directories
644   rw-r--r--   ordinary files
600   rw-------   private keys and secrets
700   rwx------   private directories
4755  rwsr-xr-x   setuid program (runs as its owner)

Each digit adds up read (4), write (2) and execute (1) for the owner, the group and everyone else. An optional fourth digit at the front sets setuid (4), setgid (2) and the sticky bit (1).

Symbolic mode: u, g, o, a and + - =

Besides numbers, chmod takes a symbolic mode, which changes some bits and leaves the rest alone. It is written as who, an operator, and which permissions:

  • Who: u (the owner), g (the group), o (others), a (all three). Leaving it out means all, minus anything blocked by your umask.
  • Operator: + adds, - removes, = sets exactly and clears the rest for that group.
  • Permissions: r, w, x, plus s (setuid or setgid), t (sticky) and X.
chmod u+x deploy.sh          # owner may now run it; nothing else changes
chmod go-w config.php        # take write away from group and others
chmod u=rw,go=r notes.txt    # exactly 644
chmod g+s shared/            # setgid on a directory (see /chmod-calculator/2775/)
chmod -R u=rwX,go=rX site/   # folders 755, files 644 (unless already executable)

(Linux and macOS commands, not run on this page.) Capital X adds execute only to directories and to files that already have execute for someone. That makes chmod -R a+rX the safe way to open up a tree: folders become searchable without every text file becoming executable, which is what chmod -R 755 would do.

The difference that matters: a number replaces the whole mode, while + and - are relative. chmod 644 script.sh silently removes execute; chmod go-w script.sh touches nothing but write.

umask: the default for new files

New files are not created with 777. Programs usually ask for 666 for files and 777 for directories, and the process's umask then removes bits: the result is the requested mode AND NOT the umask. With the common umask 022, files come out as 644 and directories as 755. With 027 others get nothing: 640 and 750.

print(oct(0o666 & ~0o022))                # → 0o644   new file with umask 022
print(oct(0o777 & ~0o027))                # → 0o750   new directory with umask 027
print(oct(0o666 & ~0o027))                # → 0o640
printf '%04o\n' $(( 0666 & ~0022 ))    # → 0644   default file mode under umask 022
printf '%04o\n' $(( 0777 & ~0077 ))    # → 0700   default directory mode under umask 077
echo $(( 8#755 ))                      # → 493

It is a mask, not a subtraction. With umask 033 a file asked for as 666 becomes 644, not 633, because the execute bits it masks were never there. Run umask to see yours and umask -S for the symbolic form; the setting lasts for that shell and anything it starts.

Reading ls -l

The first column of ls -l is the mode as ten characters:

-rwxr-xr-x  1 deploy www-data  2048 Nov  3 09:14 deploy.sh
drwxrws---  2 deploy www-data  4096 Nov  3 09:10 uploads

The first character is the type: - a regular file, d a directory, l a symbolic link. Then come three groups of three for the owner (deploy), the group (www-data) and everyone else. In the second line the s in the group's execute slot is setgid, so files created in uploads belong to www-data; a capital S would mean setgid without execute, which is nearly always a mistake. A trailing + after the ten characters means extra ACL entries, which getfacl shows.

On a directory the bits mean something slightly different: r lists names, w creates, renames and deletes entries, and x lets you enter the directory and reach files inside it. That is why 711 (see 711) lets others open a file whose path they already know without listing the folder.

To get the number for an existing file, run stat -c '%a %n' file on Linux or stat -f '%Lp %N' file on macOS. In code:

print(int('755', 8))                      # → 493   the mode as a plain integer
print(oct(0o4755))                        # → 0o4755
print(stat.filemode(0o100644))            # → -rw-r--r--   0o100000 marks a regular file
print(stat.filemode(0o040755))            # → drwxr-xr-x   0o040000 marks a directory
print(stat.filemode(0o104755))            # → -rwsr-xr-x
console.log(parseInt('755', 8));             // → 493
console.log((0o640).toString(8));            // → 640
console.log((755).toString(8));              // → 1363   what fs.chmodSync(f, 755) really sets: write 0o755
console.log((0o644 & ~0o022) === 0o644);     // → true

chmod or chown?

chmod changes what the owner, the group and others may do. chown changes who the owner and group are. When a web server gets "Permission denied" on an upload folder, the clean fix is usually to give the folder to the right group (chown -R deploy:www-data uploads) and allow that group to write (chmod 2775 uploads), not to open it to everyone with 777. Only root can give a file to another user; an ordinary user can change the group to any group they belong to.

Two more gotchas. Permissions on a symbolic link itself are ignored, and chmod follows the link to its target. And on GNU systems a 3 or 4 digit mode leaves a directory's setgid bit in place, so chmod 755 on a 2775 directory still shows s; use chmod g-s or five digits, chmod 00755, to clear it.

Questions

What does chmod 755 mean?

The owner can read, write and execute; the group and everyone else can read and execute.

What permissions should a website use?

Typically 755 for folders and 644 for files, with configuration files that hold secrets set tighter, such as 600 or 640.

Why does SSH refuse my key file?

SSH ignores private keys that other users can read. Run chmod 600 on the key and chmod 700 on the ~/.ssh directory.

What does chmod +x do?

It adds execute permission. Without a u, g or o in front it applies to all three, except where your umask blocks it, so with umask 022 a 644 file becomes 755. Use u+x to make a file executable for its owner only.

Why does chmod not work on Windows or in Git Bash?

Windows file systems have no Unix permission bits. Git Bash fakes them, so chmod may appear to succeed while nothing is stored. In Git, use git update-index --chmod=+x file to record the executable bit.

Should I pass 755 or 0o755 to chmod in code?

Write it as octal: 0o755 in Python and JavaScript, 0755 in C, Go and PHP. A plain 755 is the decimal number 755, which is octal 1363, so the file gets a sticky bit and odd permissions. Node also accepts the string "755", which it reads as octal.