Linux / Unix File Permissions Explained | Warp
Introducing Warp Factories
open, flexible infrastructure for building your own cloud software factory. Learn More
File permissions are "bits" set on any file in a Unix system. Here is a reference sheet of some of the most common permissions bits:
| Permissions | Numeric | Meaning |
|---|---|---|
| drwxr-xr-x | 755 | Directory, accessible by everyone but only writable by the owner |
| -rw-r--r-- | 644 | File, readable by everyone but can only be modified by the owner |
| -rwxrwxrwx | 777 | File is readable (and executable) by anybody |
| -rw------- | 600 | File can only be accessed by the owner, inaccessible to everyone else |
A file's permissions define what the owner can do, what the owner's group can do, and what the rest of the world can do to a file --- read, write, or execute it. For Unix purposes, a directory is also a file, and you can't cd into a directory that doesn't have the executable permission set for your user.
To check permissions of all the files in a directory, you can run ls -l to perform a long format listing. This shows the permissions for each file and directory in the first column. These are shown as -ooogggwww, where o is "owner," g is "group," and w is "world."
In the case of a directory, the first single indicator will be d. Each one of the other types gets three positions: read, write, and execute. If a r, w, or x is present in its respective position, then that user has access to that permission; otherwise, you'll see a dash (-). So a file that was readable and writable by its owner but inaccessible to other users would look like -rw-------.
Understanding file permissions as numbers
-rw------- can be represented numerically as 600. The 6 translates as rw for the user and the 0s translate as "no access" for group and world, respectively.
When using numeric representation, the numbers can be three or four digits. In the case of four digits, the first digit is used to set setuid, setgid, or sticky bit. The last three digits represent a combination of read, write, and execute added together.
- 4 = r (read)
- 2 = w (write)
- 1 = x (execute)
For each group, you add the three numbers together to create a single-digit representation of the permissions for that group. For example:
- 0 means no permissions
- 4 means read only (4)
- 5 means read and execute (4 + 1)
- 6 means read and write (4 + 2)
- 7 means all permissions (read, write, and execute, or 4 + 2 + 1)
A file that is executable by the owner and read-only for everyone else would be -rwxr--r--, represented as 0744, with 7 (4 + 2 + 1) for the user and 4 for group and world.
Standard permissions for files and directories
The standard permissions for a regular file are -rw-r--r--, or, numerically, 644, which gives the file owner permission to read and write, and the group and world permission to read only.
The standard permissions for a directory are drwxr-xr-x, or 755. This gives the owner permission to write, and the owner, group, and world permission to read and "execute" them or, in this case, cd into them.
An executable file, such as an executable shell script with proper shebang or a binary, gets the x bit set for the appropriate user. In most cases, this is everybody, which translates as -rwxr-xr-x, or 755. To make a file fully readable, writable, and executable to everybody, you would want -rwxrwxrwx, or 777 file permissions. This is generally ill-advised, as you don't want the entire world to have write access to any file.
Setting and modifying file permissions is done using the chmod command, which we discuss further in another post.