The person who owns the file or directory.
g
):o
):r
):w
):x
):Permissions for file.txt
are displayed, e.g. with the ls -l
command:
$ ls -l
-rwxr-xr-- 1 user group 4096 Dec 2 10:00 file.txt
Breakdown:
-rwxr-xr--
: Permission string.The permission string is read from left to right and consists of the following parts:
-
): Regular file (d
for directory).rwx
): Read, write, and execute for the owner.r-x
): Read and execute for the group.r--
): Read-only for others.Use the chmod
command to change file or directory permissions.
chmod u+rwx file.txt # Add read, write, and execute to the owner
chmod g-w file.txt # Remove write permission from the group
chmod o+x file.txt # Add execute for others
chmod a+r file.txt # Add read permission for everyone (all users)
Permissions are represented by numbers:
`r = 4`, `w = 2`, `x = 1`, `- = 0`
You sum these values to set permissions:
7 (rwx)
: Read + Write + Execute6 (rw-)
: Read + Write5 (r-x)
: Read + Execute4 (r--)
: Read-onlychmod 754 file.txt # Owner=rwx (7), Group=r-x (5), Others=r-- (4)
Understanding permissions in binary representation helps clarify how octal mode works. Each permission bit (r
, w
, x
) can be represented as binary digits (0
or 1
), forming a 3-bit binary string.
Permission | Binary | Octal | Meaning |
---|---|---|---|
--- | 000 | 0 | No access |
--x | 001 | 1 | Execute |
-w- | 010 | 2 | Write |
-wx | 011 | 3 | Write+Exec |
r-- | 100 | 4 | Read |
r-x | 101 | 5 | Read+Exec |
rw- | 110 | 6 | Read+Write |
rwx | 111 | 7 | All (Full) |
Consider the permission string -rwxr-xr--
. Convert each permission triplet to binary:
rwx
): 111
(binary) → 7
(octal)r-x
): 101
(binary) → 5
(octal)r--
): 100
(binary) → 4
(octal)Thus, the octal representation is:
chmod 754 file.txt
Let’s say we want a file permission of rw-r--r--
:
rw-
): 110
(binary) → 6
(octal)r--
): 100
(binary) → 4
(octal)r--
): 100
(binary) → 4 (octal)The resulting octal code would be:
chmod 644 file.txt
chown
(Change Owner):
chown user file.txt # Change the owner to 'user'
chown user:group file.txt # Change owner and group
chgrp
(Change Group):
chgrp group file.txt # Change the group only
s
): Run the file as the owner, not the user running it.s
): Run the file with the group’s permissions.t
): On directories, only the owner can delete files.Example:
chmod u+s file.sh # Set SetUID
chmod g+s dir/ # Set SetGID
chmod +t /tmp # Set Sticky Bit
Special permission bits (SetUID
, SetGID
, and Sticky Bit
) also follow binary logic:
Special Bit | Binary | Octal |
---|---|---|
--- | 000 | 0 |
--t | 001 | 1 |
-s- (SetGID) | 010 | 2 |
s-- (SetUID) | 100 | 4 |
For example, chmod 1755
would correspond to:
1
→ Sticky Bit --t
on a directory7
→ Owner rwx
5
→ Group r-x
5
→ Others r-x
Sources and recommended, further resources on the topic:
License: Permissions in Linux Explained by Jonas Jared Jacek is licensed under CC BY-SA 4.0.
This license requires that reusers give credit to the creator. It allows reusers to distribute, remix, adapt, and build upon the material in any medium or format, for noncommercial purposes only. To give credit, provide a link back to the original source, the author, and the license e.g. like this:
<p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a property="dct:title" rel="cc:attributionURL" href="https://www.ditig.com/publications/permissions-in-linux">Permissions in Linux Explained</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://www.j15k.com/">Jonas Jared Jacek</a> is licensed under <a href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="license noopener noreferrer">CC BY-SA 4.0</a>.</p>
For more information see the DITig legal page.