chmod 755 shared ran without an error on a test container, and afterward the directory’s mode read 2755. The command asked for three digits and the system kept a fourth, a setgid bit that had been there before and stayed on purpose. Permission numbers look like arbitrary codes copied from forum answers, and most of the time they behave that way. They are actually three or four octal digits, each one a small sum, and once the sums make sense the odd cases like that 2755 stop being surprises. Every command below was run on an Ubuntu 24.04 test container with GNU coreutils 9.4, as root and as an unprivileged test user.
Three digits, nine switches
Read is 4, write is 2, execute is 1, and each digit is a sum
The GNU coreutils manual lists the values: for the owner “400 Read,” “200 Write,” and “100 Execute/search”; for the group 40, 20 and 10; for everyone else 4, 2 and 1. Each set of three bits, in the manual’s words, is “represented as one octal digit.” So a digit is just read, write and execute added up: 7 is 4+2+1, 6 is 4+2, 5 is 4+1, 4 is read alone.
A few lines of Python print the common modes as raw bits, with the special digit first:
0755 -> special 000 user 111 group 101 other 101
0644 -> special 000 user 110 group 100 other 100
0600 -> special 000 user 110 group 000 other 000
0700 -> special 000 user 111 group 000 other 000
4755 -> special 100 user 111 group 101 other 101
1777 -> special 001 user 111 group 111 other 111
2775 -> special 010 user 111 group 111 other 101
Applied to a file and read back with stat -c '%a %A':
chmod 755 f -> 755 -rwxr-xr-x
chmod 644 f -> 644 -rw-r--r--
chmod 600 f -> 600 -rw-------
chmod 400 f -> 400 -r--------
chmod 0 f -> 0 ----------
755 is the usual mode for programs and directories: the owner can do everything, others can read and run or enter. 644 is the usual mode for ordinary files, owner writes and everyone reads. 600 is for secrets, owner only: private keys, and the passwords and API tokens a self-hosted Docker Compose service reads from disk. The symbolic form says the same thing in letters, and chmod u=rw,go=r f produced 644 on the test file. Leading zeros are optional; the manual’s example is that “Mode ‘0055’ is the same as mode ’55’.”

The same bits mean something else on a directory
Read lists the names, execute opens the way through, write decides what gets deleted
A directory is a file holding a list of names, and the three bits act on that list. The path_resolution(7) man page says the third bit is “execute permission in case of ordinary files, or search permission in case of directories,” and that without search permission on a directory in the path, “an EACCES error is returned.” A test directory box held one readable file, note.txt, mode 644. With the directory at 744, the test user could read the list but not reach the file:
$ ls /tmp/p45a/box # box is 744, as user tester
note.txt
$ cat /tmp/p45a/box/note.txt
cat: /tmp/p45a/box/note.txt: Permission denied
At 711 it flipped:
$ ls /tmp/p45a/box # box is 711
ls: cannot open directory '/tmp/p45a/box': Permission denied
$ cat /tmp/p45a/box/note.txt
secret
Without read, the names can’t be listed, but anyone who already knows a name can walk straight to it. Execute on a directory works like a key to a hallway with the lights off.
Write on a directory controls creating, renaming and deleting entries. The unlink(2) man page lists EACCES when “Write access to the directory containing path is not allowed,” which means the file’s own mode doesn’t enter into it. A root-owned file at mode 444 sat in a directory owned by the test user:
444 root drop/rootfile
tester deleted a 444 root-owned file because tester owns the directory
The file was read-only for everyone, and it was gone anyway.
The fourth digit: setuid, setgid and sticky
4000, 2000 and 1000, each with its own trap
The manual lists the special bits as “4000 Set user ID,” “2000 Set group ID,” and “1000 Restricted deletion flag or sticky bit.” ls shows them by replacing an execute slot: s for setuid or setgid with execute, t for sticky. When the underlying execute bit is missing, the letter is capitalized as a warning that the bit is set but can’t do anything:
chmod 4755 f -> 4755 -rwsr-xr-x
chmod 2775 f -> 2775 -rwxrwsr-x
chmod 1777 f -> 1777 -rwxrwxrwt
chmod u+s on a 644 file -> 4644 -rwSr--r--
chmod 1755 d -> 1755 drwxr-xr-t
Setuid makes a program run as its file’s owner. A copy of /usr/bin/id made setuid-root and run by the test user reported:
$ /tmp/p45a/id-suid -u # effective UID
0
$ /tmp/p45a/id-suid -ru # real UID
30033
Effective UID 0, root, for an unprivileged user. Any program installed that way hands its powers to whoever runs it, which is why a stray setuid-root binary is a security hole. The test copy had its setuid bit removed right after.
A shell script with the same bit behaves differently. The execve(2) man page says “Linux (like most other modern UNIX systems) ignores the set-user-ID and set-group-ID bits on scripts.” A root-owned script at 4755 that printed id -u gave the test user its own UID, 30033, every time.
On a directory, setgid changes group inheritance. The inode(7) man page says files created there “inherit their group ID from the directory, not from the effective group ID of the creating process.” That is the standard setup for a shared team folder, usually mode 2775. The sticky bit on a directory means files “can be renamed or deleted only by the owner of the file, by the owner of the directory, and by a privileged process.” It is the reason /tmp is 1777 and nobody can delete anybody else’s files there:
1777 drwxrwxrwt sticky
666 -rw-rw-rw- sticky/rootfile
tester could write (666)
rm: cannot remove '/tmp/p45a/sticky/rootfile': Operation not permitted
without sticky bit: tester deleted it
The test user could write to the root-owned 666 file but couldn’t delete it while the sticky bit was on. Changing the directory to 777 removed that protection, and the delete went through.

The umask: why new files come out 644
A mask, applied with AND NOT, that people keep treating as subtraction
New files don’t start at 755 or 644 by choice. Programs usually ask for 666 for files and 777 for directories, and the process umask turns bits off. The umask(2) man page says “permissions in the umask are turned off,” gives the typical default as “octal 022,” and shows the arithmetic: “0666 & ~022 = 0644.” On the test container, four umask values produced:
umask 022: file 644 -rw-r--r-- | dir 755 drwxr-xr-x
umask 002: file 664 -rw-rw-r-- | dir 775 drwxrwxr-x
umask 077: file 600 -rw------- | dir 700 drwx------
umask 027: file 640 -rw-r----- | dir 750 drwxr-x---
Python reproduced every one of those as requested & ~umask. A common shortcut says “subtract the umask from 666,” and with 022 it happens to work. With an odd digit it doesn’t:
subtraction myth with umask 033 on a file: 666-033 = 0o633 vs 666&~033 = 0o644
actual with umask 033: 644 -rw-r--r--
Subtraction predicts 633, rw--wx-wx, which would hand group and others write and execute permission out of nowhere while taking their read away. The real result was 644, because a mask can only switch bits off. The umask also never adds execute to a file; a program that wants an executable file has to ask for it, which is why a freshly written script needs chmod +x before a timer or cron job can run it; the systemd timers vs cron guide assumes that step is already done.
Where people get burned
Recursive 755, a setgid bit that won’t leave, and an SSH key that gets ignored
chmod -R 755 on a web root. It makes every file executable along with every directory. A test tree of two 600 files and two 700 directories, after each approach:
$ chmod -R 755 site $ chmod -R u=rwX,go=rX site2
755 d site 755 d site2
755 d site/css 755 d site2/css
755 f site/css/a.css 644 f site2/css/a.css
755 f site/index.html 644 f site2/index.html
Capital X, per the coreutils manual, affects execute “only if the file is a directory or already had execute permission.” It gives directories their search bit and leaves CSS files alone.
The setgid bit that chmod 755 won’t clear. That was the opening example. The chmod(1) man page says “For directories chmod preserves set-user-ID and set-group-ID bits unless you explicitly specify otherwise,” and clearing them numerically takes an extra leading zero. On the test container:
start: 2775 drwxrwsr-x
chmod 755 shared -> 2755 drwxr-sr-x (setgid survived)
chmod 0755 shared -> 2755 drwxr-sr-x
chmod 00755 shared -> 755 drwxr-xr-x
chmod g-s shared -> 775 drwxrwxr-x
One leading zero wasn’t enough; two were. g-s is the readable way to do it. The flip side is that chmod 755 on a regular file does clear the special bits, so the same command behaves differently on files and directories.
An SSH key at 644. The ssh(1) man page says private keys “should be readable by the user but not accessible by others” and “ssh will simply ignore a private key file if it is accessible by others.” A fresh ed25519 key set to 644 on the test container (OpenSSH 9.6p1) produced:
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
Permissions 0644 for 'testkey' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "testkey": bad permissions
chmod 600 fixed it on the next run. Copying keys between machines with tools that don’t preserve modes is the usual way this happens.

When the numbers aren’t the whole story
ACLs, capabilities and root
The strongest argument against memorizing any of this is that the nine bits are no longer the only gate. The umask man page itself notes that a default ACL on the parent directory causes the umask to be ignored. Root gets past most of these checks, too: the capabilities(7) man page says privileged processes “bypass all kernel permission checks,” and CAP_DAC_OVERRIDE alone lets a process “Bypass file read, write, and execute permission checks.” Every refusal shown above came from the unprivileged test user for that reason. And the special bits are policed by more than chmod: the chmod man page says the set-group-ID bit is cleared on regular files when the file’s group doesn’t match the user’s, and execve notes that a nosuid mount makes the kernel ignore setuid bits or refuse to run the program, depending on version.
None of that makes 755 and 644 less useful. It means ls -l answers “what do the bits say,” and a permission error that doesn’t match the bits sends the search to ACLs, mount options or the user the program is really running as.
The setuid copy of id from the test above printed a 0 for a user who had no business being root, from a file that looked like every other program in the directory. How many setuid files are on your own machines, and could you name what each one is for?
Sources
- GNU coreutils manual, Numeric Modes: https://www.gnu.org/software/coreutils/manual/html_node/Numeric-Modes.html
- GNU coreutils manual, Conditional Executability: https://www.gnu.org/software/coreutils/manual/html_node/Conditional-Executability.html
- chmod(1) man page: https://man7.org/linux/man-pages/man1/chmod.1.html
- path_resolution(7) man page: https://man7.org/linux/man-pages/man7/path_resolution.7.html
- unlink(2) man page: https://man7.org/linux/man-pages/man2/unlink.2.html
- execve(2) man page: https://man7.org/linux/man-pages/man2/execve.2.html
- inode(7) man page: https://man7.org/linux/man-pages/man7/inode.7.html
- umask(2) man page: https://man7.org/linux/man-pages/man2/umask.2.html
- ssh(1) man page: https://man7.org/linux/man-pages/man1/ssh.1.html
- capabilities(7) man page: https://man7.org/linux/man-pages/man7/capabilities.7.html
