chmod 622: Write Without Read, and the Old Terminal Mode
622 is rw--w--w-: the owner can read and write, while the group and everyone else can write but not read. It is a genuine mode with almost no modern use, and it survives mainly as the historical mode of a writable terminal device.
At a glance
- Octal
- 622, written 0622 in four digit form
- Symbolic
- u=rw,g=w,o=w
- On a file
- -rw--w--w-
- On a directory
- drw--w--w-, unusable because no class has execute
- Owner
- Read and write
- Group
- Write only. Can destroy the contents without ever seeing them
- Others
- Write only. Same capability, extended to every local account
In detail
Write without read is a real capability and an uncomfortable one. An account with the write bit and not the read bit can truncate the file to nothing, append to it, or overwrite it from the start, but cannot open it to see what was there. It is destructive access without visibility, which is why almost nothing is designed around it.
Its historical home is the terminal device. On older systems the write utility was not setgid, so allowing other users to send a message to your terminal meant opening the device itself to everyone, and mesg y produced a 622 device node. Current systems use a setgid write program with the terminal owned by the tty group at 620, which grants the same thing to one small group instead of to the world.
As an append only log this does not work either, despite the appeal of the idea. Nothing in the mode forces appending: a process with write permission can seek to the beginning and overwrite. Append only behaviour comes from opening the file with the append flag, or from the file attribute set by chattr +a, not from the permission bits.
On a directory, 622 is inert. No class has the execute bit, so nothing can traverse into it, and the write bits that appear to allow creating entries cannot be exercised because the path cannot be resolved. As with every unusable directory mode, the digits look meaningful and the behaviour is a flat refusal.
If you have found 622 on a regular file, it is worth treating as an incident rather than a curiosity. It is not a mode any package sets, and world write on anything is a finding in its own right. Decide who really needs to write, give that group the access explicitly, and take the others bits back to zero.
Examples
chmod 622 message.log
chmod u=rw,g=w,o=w message.log-rw--w--w- 1 alice alice message.log
$ whoami
bob
$ cat message.log
cat: message.log: Permission denied
$ echo destroyed > message.log # succeeds, file is now empty$ tty
/dev/pts/3
$ ls -l /dev/pts/3
crw--w---- 1 alice tty 136, 3 /dev/pts/3
Mode 620, group tty. The write program is setgid tty, so it
can deliver a message without the device being open to all.Things that catch people out
- Write permission does not imply append only. Anything that can write can also truncate, so 622 gives away destruction rather than contribution.
- A process that writes and then reads back to verify will fail on its second step. Tools frequently do this without documenting it, so the failure looks unrelated to permissions.
- 622 is world writable and will be reported by any hardening scan alongside 666 and 777. There is no explanation that makes it acceptable on a regular file.
- 622 on a directory does nothing at all, because traversal needs the execute bit that none of the three classes has here.
Try it: Chmod Calculator
Tick the nine permission boxes, or type an octal or symbolic value, and get the three digit and four digit octal, the ls -l rendering and the exact chmod command back.
Chmod Calculator
LOCAL · Browser-OnlyCalculate Unix file permissions with an interactive chmod builder
Permission Matrix
| Entity | Read (4) | Write (2) | Execute (1) | Octal | Symbolic |
|---|---|---|---|---|---|
| Owner (u) | 7 | rwx | |||
| Group (g) | 5 | r-x | |||
| Others (o) | 5 | r-x |
Special Bits
Advanced permission flags for executables and directories
Generated Permissions
755rwxr-xr-x-rwxr-xr-xchmod 755 filenamechmod u=rwx,g=rx,o=rx filenamePermission Breakdown
Owner (u)
7rwx- - Read files / list directory contents
- - Write / modify / delete
- - Execute / traverse directory
Group (g)
5r-x- - Read files / list directory contents
- - Execute / traverse directory
Others (o)
5r-x- - Read files / list directory contents
- - Execute / traverse directory
Common Permissions Reference
| Octal | Symbolic | Meaning |
|---|---|---|
777 | rwxrwxrwx | Full access for everyone |
755 | rwxr-xr-x | Owner full, others read and execute |
750 | rwxr-x--- | Owner full, group read and execute |
700 | rwx------ | Owner full access only |
666 | rw-rw-rw- | Read and write for everyone |
644 | rw-r--r-- | Owner read/write, others read only |
600 | rw------- | Owner read/write only |
555 | r-xr-xr-x | Read and execute for everyone |
444 | r--r--r-- | Read only for everyone |
400 | r-------- | Owner read only |
Related File permissions
All file permissions →chmod 666: World Writable Files and the Few Legitimate Ones
666 lets every account read and write the file with no execute bit anywhere. Why it is wrong for regular files and right for a handful of device nodes.
chmod 600: Owner Only Read and Write for Keys and Secrets
600 gives the owner read and write and nobody else anything. The mode SSH, PostgreSQL and other tools insist on for files holding credentials.
chmod 644: The Default File Mode and When to Change It
644 gives the owner read and write and everyone else read only. Why it is the default for files under a 022 umask, and the cases where it is wrong.
chmod 555: Read and Execute With No Write for Anyone
555 removes the write bit from the owner as well as everyone else. What that protects against, what it does not, and how real immutability is done.
chmod 550: Programs a Service Can Run but Cannot Change
550 gives the owner and group read and execute and everyone else nothing. The mode for a privileged script that a service must run but must not modify.
chmod 500: Owner Only Read and Execute, Nothing Else
500 lets the owner read and execute but not write, and gives group and others nothing. A guard against accidental edits and a way to freeze a directory.
Tools for this
- Chmod Calculator Free online chmod calculator - calculate Unix file permissions with an interactive chmod builder