"Linux Permissions : A Beginner's Guide to Access Control"

"Linux Permissions : A Beginner's Guide to Access Control"

Introduction:

  • Linux is a multi-user operating system which means many users can access it at a time.

  • It can be used in servers and mainframes without any need for modification.

  • As the Linux operating system is used by multiple users at a time that means any user can corrupt, remove or change data so to avoid a user accessing any other user’s confidential or crucial files and data, Linux has great security features.

  • Permission specifies what a particular user can or cannot do with respective files and directories. These permissions help to create a secure environment for the users.

Classes of Linux Files:

There are three types of classes:

  • User or Owner: A person who creates a file is called a user or an owner of that particular file. The User has no impact on the actions of other users. The ownership can be specifically transferred or granted to any other user also.

  • Group: A group can have multiple users. Every user belonging to a particular group would have the same privileges and access permissions for a particular file.

  • Others: It refers to all other users that can access the file. Setting permission for others means setting permission for the world. It refers to those who are not the owners or not in a group, i.e., the general public

Permission of Linux Files:

  • Read (r): The read permission allows the user to open the file and read its contents. However, the user is not allowed to modify or change the file’s contents.

  • Write (w): The write permission allows the user to modify or change the file’s contents.

  • Execute (x): This permission allows the user to execute the program or the code. If a user lacks execution permissions, they can read or modify the code, but they will be unable to execute it.

Now lets us see how to read the permissions that appeared on the terminal.

Example:

If we enter the command,

command= ls -l(Long List)

output= -rw-rw-r-- 3 ubuntu ubuntu 4096 Jul 21 11:40 devops

The ls – l command gives -

  • The first column indicates permissions to the file.

  • The second indicates the link.

  • The third indicates user

  • The fourth indicates the user group

  • The fifth column indicates the size of the file.

  • The sixth column indicates the date and time of file creation.

  • The seventh column indicates the file name.

    Detail information about the permissions:

    Example : -rw-rw-r--

Linux Commands Cheat Sheet | Linux Training Academy

  • The first depicts that a file is selected.

  • Then there are nine characters: 'r' refers to read permission, 'w' refers to write permission, 'x' refers to execute permission, and refers to no permission.

  • The first three characters depict the permission given to the owner. For example, in the above example, rw- refers that the owner can read the file’s contents and change or modify the file but cannot execute it.

  • The next three characters depict the permission given to the group. For example, in the above screenshot, rw- refers that the group members can read the file and modify or change the file but cannot execute the file.

  • The last three characters depict the permission given to the world or other users. For example, in the above screenshot, r-- shows that other users can only read the file. They can neither modify nor execute the file or program.

Lets us see How we can Change Security Permission :

  • We can change the permission by using the 'chmod' command.

    Syntax:

    chmod [permission] [path]

  • For change permission:

    1) To add read permission to the user

    Syntax:

    #chmod u+r /file_name

    2) To add read and write permission to the group

    Syntax:

    #chmod g+rw /file_name

    3) To remove read permission to others

    Syntax:

    #chmod o-r /file_name

  • To change ownership:

    Syntax:

    #chmod <user name> <file/directory name>

  • To change group ownership:

    Syntax:

    #chmod <group name> <file/directory name>

    To set permission with a numeric value:

    The first digit in the octal number is used to set setuid, setgid, or sticky bit. Each remaining digit set permission for the owner, group, and world as follows:

    • 4 = r (Read)

    • 2 = w (Write)

    • 1 = x (eXecute)

So you end up creating the triplets for your user by adding the digits.

For e.g.

  • To represent rwx triplet use 4+2+1=7

  • To represent rw- triplet use 4+2+0=6

  • Represent r-- triplet use 4+0+0=4

  • To represent r-x triplet use 4+0+1=5

Useful commands for your Linux Part 1 | Terminal Root

Let us try to understand the chmod command:

  • syntax:
    $ chmod ### {file1|dir1}

    Where

    • Each # digit represents permissions for an access level for Linux user, group and others.

    • The digit is calculated by adding together numbers for each permission.

Example:

In this example, I am setting read, write, and execute permissions for the user, read and execute permissions for the group, and no permission for others on devops file

chmod -v 750 /devops