Linux file permissions

Commands:

chmod
chmod is used to change access permissions to files/directories. For example:
To change the permissions of the directory some-directory to 777, type:
chmod 777 some-directory
To recursively change any sub-directories and their contents, type:
chmod 777 -R some-directory/
chown
chown is used to change user and/or group ownership of files/directories. For example:
To change the user ownership of the directory some-directory to user1, type:
chown user1 some-directory
To recursively change any sub-directories and their contents, type:
chown user1 -R some-directory/
Tip: By adding a colon after the user, chown can be used to change the group and user ownership simultaneously. For example, type:
chown user1:group1 some-directory
chgrp
chgrp is used to change group ownership of files/directories. For example:
To change the group ownership of the directory some-directory to group1, type:
chgrp group1 some-directory
To recursively change any sub-directories and their contents, type:
chgrp group1 -R some-directory/

Access permissions:

There are three types of access rights available in Linux:

Read (r)
Write (w)
Execute (x)

Access permissions can be easily controlled by using a 3-digit value together with the command chmod.

This 3-digit value is made up from three separate groups, each with their own value that specifies the type of access that is available. The groups are:

User - the owner of the file
Group - the group owner of the file
Others - other users not in the group

The values range from 0 to 7.

The table below shows the full list of values next to their relevant access permissions:

No. Read (r) Write (w) Execute (x)
0 Denied Denied Denied
1 Denied Denied Allowed
2 Denied Allowed Denied
3 Denied Allowed Allowed
4 Allowed Denied Denied
5 Allowed Denied Allowed
6 Allowed Allowed Denied
7 Allowed Allowed Allowed

So, if a value of 7 is specified, the relevant group can read, write and execute. If 4 is specified, the relevant group can only read.

The the first number is assigned to User, the second to group and the third to others.

Examples:

644
Owner can Read and Write
Group can Read
Others can Read
775
Owner can Read, Write and Execute
Group can Read, Write and Execute
Others can Read and Execute

Go back to the How-to Guides main page.

Search

Starter website

Offering small businesses and individual users the opportunity to have their own website on the internet, our 'starter websites' are available for only £150.

new site offer

To find out more and to see an example of the type of site offered, view our example starter website page.