1.18 List, set, and change standard file permissions

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.

Types of Permissions

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.

Alphabetic Notation

Each permission is represented by a single letter:

  • r = read permissions
  • w = write permissions
  • x = execute permissions
  • - (dash) = specific permission has not been assigned

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)

  • user - the owner of the file
  • group - a user group
  • others - anyone else that has a login to the computer

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.
  • - = regular file
  • d = directory
  • l = link
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

Octal Notation

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:

  • 4 = read permissions (r)
  • 2 = write permissions (w)
  • 1 = execute permission (x)
  • 0 = permission not assigned (-)
owner can read, write and execute; others can read and execute
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
-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

Changing Permissions

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

  • u - user
  • g - group
  • o - others
  • a - all above (ugo)
# 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

CentOS 7

No features.

openSUSE Leap 42.3

No features.

Ubuntu 17.04

No features.

Publication/Release Date: Jul 18, 2017

Advertisement