Articles

Setting Linux Permissions

In this article, we will show how to easily calculate Linux permissions on files.

Each file in Linux has three sets of permissions.

The first set is ‘Owner’ which is the set that applies to the owner of the file.
This is typically the person who created the file.


The next set is ‘Group’, which is the set that applies to a user who isn’t the Owner but is in the Group that owns the file.


The last set is ‘Everyone’, which is the set of permissions that applies to anyone that isn’t the Owner and isn’t in the matching Group.

The Long Way

You may see permissions written like so:
rwxr-xr–
‘x’ stands for execute, ‘w’ stands for write and ‘r’ stands for read. A dash means that the permission isn’t set.
Starting from the left, the first three are for the Owner, the second three are for the Group and the last three are for everyone else.
In this case, the Owner can read, write and execute the file. The Group can only execute and read and everyone else can only read the file.

The Short Way

You may also hear people talk about setting permissions to ‘755’, for example. This is a shorthand way of expressing permissions.
Many people struggle with how to calculate this, but it’s actually quite simple. You’ll need to know your binary though.

  • Each set of permissions is represented by one digit, so the Owner is 7, the Group is 5 and Everyone is 5
  • 7 in binary is 111. Notice that there are three digits in binary and there are three permissions, rwx.
  • Each binary digit represents one of the permissions. A 1 means that permission is enabled, a 0 means it is disabled.
OWNERGROUPEVERYONE
r w xr w xr w x
1 1 11 0 11 0 1
755

Owner can read, write and execute.
Group can read and execute, but not write.
Everyone can read and execute, but not write.

OWNERGROUPEVERYONE
r w xr w xr w x
1 1 11 0 0000
740

Owner can read, write and execute.
Group can read, but not write or execute.
Everyone can do nothing at all.

The Shorter Way

Just remember that:
Read = 4
Write = 2
Execute = 1
Then just add them up to get the final number for that permission.
For example:
Read and Write but not Execute is: 4 + 2 = 6
Write and Execute but not Read is: 2 + 1 = 3
Read and Execute but not Write is: 4 + 1 = 5