Understanding Linux File Permissions And Using chmod

So file permissions determine who can read, alter or execute a file (executing a file can be done if it contains something to execute such as a script).

In order to get a look at what permissions a file has run the following in the terminal:

ls -l

This will list the contents of the directory with more detail.

Screenshot 2018-05-29 13.16.34

The above shows the properties including permissions of the text file different name.

In the centre it says root root. The first root is the user name, the second root is the group to which the user root belongs. If I were to create a second user called marc on my Kali installation, it would replace the first root. If the marc user I created was a root user the second root would still be there.

The permissions are listed on the right:

rw-r–r–

The first dash means that this is a regular file and not a directory or folder.

The r and the w mean that the root user has both read and write on the file, but not execute. This means that the root user can both open and read, and modify the file.

If the root user had execute permissions that look like this:

-rwx-r–r–

So back to:

-rw-r–r–

The second set of permissions are the permissions that belong to the group, in this case root. Users in the root group can read the file.

The last set permissions:

-rw-r–r

refer to any other user who is not the owner of the file or in the root group.

chmod

You can use the terminal command chmod to change the permissions of a file. However it is necessary to take a minute to understand how to change the permissions to what you want.

 

7 = read & write & executebecause 4(read) + 2(write) + 1(execute) = 7

6 = read & write because 4(read) + 2(write) = 6

5 = read & execute because 4(read) + 1(execute) = 5

4 = read

3 = write & execute because 2(write) + 1(execute) = 3

2 = write

1 = execute

0 = no permissions

So if we wanted to change the permissions of the text file different name to make it executable we might run the following in the terminal:

chmod 744 differentname

The 7 would make the file read, write and execute for the root user, read for the root group and read for everyone else.

Screenshot 2018-05-29 14.13.10.png

The above screenshot shows the before and after the chmod command on the differentname text file. Interestingly it can now be seen that the filename is green indicating that the file is available to run as a script.

One thought on “Understanding Linux File Permissions And Using chmod

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s