Permission Groups

There are below three permission groups for each file and directory

  • Owner : The Owner permissions apply only the owner of the file or directory.
  • Group : This permissions apply only to the group that has been assigned to the file or directory.
  • Others : This permissions apply to all other users on the system.

If the group of the file is the same as the user’s group, the group permission determine the access. Also if the user is not the file owner, and is not in the group, then the other permission is used.

Permission Types

Each file or directory has three permission types:

  • Read (r) : Allow a user to read the contents of the file or list the files within the directory.
  • Write (w) : It refer to a user’s capability to write or modify a file. In case of directory, it allows the user to create, rename, or delete files and modify the directory’s attributes.
  • Execute (x) : It refers to a user’s capability to execute a file or view the contents of a directory and access directories inside.

You can view the permissions of file and directory by reviewing the output of the ls -l command in the terminal. The permission in the command line is displayed as:

File permission in Linux.
  • The first character is the special permission flag that can vary.
  • Following set of three characters (rw-) is for the owner permissions.
  • Second set of three characters (r–) is for the Group permissions.
  • Last set of three characters (r–) is for the other Users permissions.

Following that grouping number displays the number of hard links to the file. The last piece is the Owner and Group assignment to which this file belongs.

Modifying the Permissions

Permissions of file and directory are edited by using the command chmod. Notation use for permission group are:

  • u : Owner
  • g : Group
  • o : Others
  • a : All users

Notation used to represent permission types are:

  • r : Read
  • w : Write
  • x : Execute

Assignment Operator + (plus) is used to add permission and – (minus) to remove the specific permissions. For an example, file named hello.txt currently has the permissions set to rw-r–r–. Now to add the execute permission for the user, execute below command

chmod u+x hello.txt

Permissions can also be modified using binary notation. The first number represents the Owner permission; the second represents the Group permissions; and the last number represents the permissions for all other users.

chmod 640 hello.txt

Each number is a binary representation of the rwx string:

  • r : 4
  • w : 2
  • x : 1

So to allow owner to have read, write and execute permissions ie rwx------, you would enter chmod 700.