Linux is a multi-user OS that is based on the Unix concepts of file ownership and permissions to provide security, at the file system level.
Each permissions category (owner, group owner, and other) can be assigned permissions that allow or restrict their ability to read, write, or execute a file.
For a regular file, read permissions are required to read the contents of a file, write permissions are necessary to modify it, and execute permissions are needed to run the file as a script or an application.
For directories, read permissions are necessary to ls
(list) the contents of a directory, write permissions are required to
modify the contents of a directory, and execute permissions allow a user to cd
(change directories) into the directory.
Linux represents these types of permissions using two separate symbolic notations: alphabetic and octal.
Each permission is represented by a single letter:
To check file permission just run ls
command with -l option
# ls -l file1.txt
-rw-r--r--. 1 root root 0 Jul 18 15:36 file1.txt
The first column shows current permissions; it has ten slots. The first slot represents the type of file. The remaining nine slots are actually three sets of permissions for three different categories of users.
The first character relates to the file type then the remaining are in 3 groups of 3 characters relating to the different access types.
These permissions are applied to (left to right)
Taking an example value of drwxrwxrwx., the meaning of each character is explained in the following tables:
d | The file type, technically not part of its permissions.
|
rwx | The permissions that the owner has over the file or directory |
rwx | The permissions that the group has over the file or directory |
rwx | The permissions that all the other users have over the file or directory |
. | A single character that specifies whether an alternate access method applies to the file. When this character is a space, there is no alternate access method. A . character indicates a file with a security context, but no other alternate access method. A file with any other combination of alternate access methods is marked with a + character. |
Each of the three permission triads (rwx in the example above) can be made up of the following characters:
permission | character | file | directory |
---|---|---|---|
read | - | cannot be read | contents cannot be shown |
r | can be read | contents can be shown | |
write | - | cannot be modified | contents cannot be modified |
w | can be modified | contents can be modified | |
execute | - | cannot be executed | cannot be accessed with cd command |
x | can be executed | can be accessed with cd command |
Using this method, each permissions category (owner, group owner, and other) is represented by a number between 0 and 7.
We arrive at the appropriate number by assigning each type of permission a numerical value:
Alphabetic | Octal | Description |
---|---|---|
for files | ||
-rw------- | 600 | only owner can read and write |
-rw-r--r-- | 644 | owner can read and write; others can read only |
-rwx------ | 700 | only owner can read,write and execute |
-rwxr-xr-x | 755 | owner can read, write and execute; others can read and execute|
-rwxrwxrwx | 777 | everyone can read, write and execute |
for directories | ||
drwx------ | 700 | only owner can read and write in directory |
drwxr-xr-x | 755 | owner can read, write in derectory; others can read and list |
Use the chmod
command to change permissions.
If you whant to use alfabetic tation you need to send to command a descripton of mode.
Mode can be
# chmod o+w file1.txt # ls -l file1.txt
-rw-r--rw-. 1 root root 0 Jul 18 15:36 file1.txt
# chmod g-r file1.txt # ls -l file1.txt
-rw----rw-. 1 root root 0 Jul 18 15:36 file1.txt
Or you can use command with octal notation
# chmod 644 file1.txt # ls -l file1.txt
-rw-r--r--. 1 root root 0 Jul 18 15:36 file1.txt
No features.
No features.
No features.