Understanding Permissions On Linux

Understanding Permissions On Linux

Permissions determine the ways different users can interact with a file or directory. When listing a file with the ls -l command, the output includes permission information. For example if we will want to use a script file called hello.sh located in the Documents directory :
First we will have to switch into the Documents Directory using this example below for instance:

admin@localhost:~$ cd ~/Documents

Now since we are in the Documents directory we will have to use the ls -l to view the permissions, the output will be something like the below example:

admin@localhost:~/Documents$ ls -l hello.sh                                  
-rw-r--r-- 1 admin admin 647 Dec 20  2017 hello.sh

Now below we will look at a review of the fields relevant to permissions.

File Type Field

- rw-r--r-- 1 admin admin 647 Dec 20 2017 hello.sh
The first character of this output indicates the type of a file.

if the first character is a -, this is a regular file. If the character was a d, it would be a directory.

Permissions Field

-rw-r--r-- 1 admin admin 647 Dec 20 2017 hello.sh
After the file type character, the permissions are displayed. The permissions are broken into three sets of three characters:

Owner

rw-r--r--
The first set is for the user who owns the file. If your current account is the user owner of the file, then the first set of the three permissions will apply and the other permissions have no effect.

-rw-r--r-- 1 admin admin 647 Dec 20 2017 hello.sh
The user who owns the file, and who these permissions apply to, can be determined by the user owner field:

Group

-rw-r--r-- 1 admin admin 647 Dec 20 2017 hello.sh
The second set is for the group that owns the file. If your current account is not the user owner of the file and you are a member of the group that owns the file, then the group permissions will apply and the other permissions have no effect.

The group for this file can be determined by the group owner field:
-rw-r--r-- 1 admin admin 647 Dec 20 2017 hello.sh

Other

-rw-r--r-- 1 admin admin 647 Dec 20 2017 hello.sh
The last set is for everyone else, any one who that first two sets of permissions do not apply to. If you are not the user who owns the file or a member of the group that owns the file, the third set of permissions applies to you.

Permission Types

here are three different permissions that can be placed on a file or directory: read, write, and execute.

  1. read(r)
    Allows for file contents to be read or copied.
  2. write(w)
    Allows for contents to be modified or overwritten. Allows for files to be added or removed from a directory.
  3. execute(x)
    Allows for a file to be run as a process, although script files require read permission, as well.

    Understanding which permissions apply is an important skill set in Linux

If You have read this far I really appreciate, Help me to grow my community:

Connect With me at Twitter | Insta | YouTube | LinkedIn | GitHub

Do share your valuable opinion, I appreciate your honest feedback!

Check out my other Blogs too:

See you in my next Blog article, Be Safe and Take care!!
Enjoy Coding