Linux File Permissions Explained [Needs Table]
Brett Terpstra
Principal Developer, Oracle
Published: 2/1/2024
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 *nix 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 a four-digit number, 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 drwx-r-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, writeable 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.
Written by
Brett Terpstra
Principal Developer, Oracle
Filed Under
Related Articles
List Open Ports in Linux
Learn how to output the list of open TCP and UDP ports in Linux, as well as their IP addresses and ports using the netstat command.
Count Files in Linux
Learn how to count files and folders contained in directories and subdirectories in Linux using the ls, find, and wc commands.
How to Check the Size of Folders in Linux
Learn how to output the size of directories and subdirectories in a human-readable format in Linux and macOS using the du command.
Linux Chmod Command
Understand how to use chmod to change the permissions of files and directories. See examples with various chmod options.
POST JSON Data With Curl
How to send valid HTTP POST requests with JSON data payloads using the curl command and how to avoid common syntax pitfalls. Also, how to solve the HTTP 405 error code.
Format Command Output In Linux
Learn how to filter and format the content of files and the output of commands in Linux using the awk command.
Create Groups In Linux
Learn how to manually and automatically create and list groups in Linux.
Switch Users In Linux
Learn how to switch between users, log in as another user, and execute commands as another user in Linux.
Remover Users in Linux
Learn how to remove local and remote user accounts and associated groups and files in Linux using the userdel and deluser commands.
Delete Files In Linux
Learn how to selectively delete files in Linux based on patterns and properties using the rm command.
Find Files In Linux
Learn how to find and filter files in Linux by owner, size, date, type and content using the find command.
Copy Files In Linux
Learn how to safely and recursively copy one or more files locally and remotely in Linux using the cp and scp command.