Linux is known as UNIX-like, which started with a multi-user operating system(OS). It means that many users can access the OS simultaneously. Linux is popular in mainframes and servers. It’s always handy to know how to file/directory permissions are handled in Linux because of its popularity and usage.

 

There are various terminologies associated with the blog. They are enlisted below:

 

1. Permission : Read(r), Write(w), Execute(x)

On a Linux system, each file/directory is determined by some access rules. These rules are governed by User Owner, Group Owner, and Other Users. The rules are associated with reading, write/modify, and executing the file.

 

  1. Read(r)

It means you can read the contents of the file

 

  1. Write(w)/Modify(m)

It means you can write and modify the contents of the file

 

  1. Execute(x)

It means you can execute file in a program


 

2. Ownership: User, Group

There are two types of ownership but three types of access.

 

1. Owner: Single User

The user who creates the file/directory is the default owner. 

2. Group: Multiple Users

The group contains multiple users. All members in this group can access files as per defined rights by permission. Group is not allowed to contain other groups as members.

3. Other: All other users

All other users who want to access are determined by rights with permission rules.


 

Visualizing and Understanding Permissions 

 

The following command list must be used in order to list files/directories with details: 

 

$ ls - l

 

The sample list that will be displayed is shown below:

 

-rwxr-xr-x 1 jvn jvn 268453 Jul 15 2020 test.png

 

Where - rwxr-xr-x is known as Permission Rule (It is the rule that governs all the users and groups) 

 

Where the first jvn is known as User Owner (Which means that the mentioned user i.e. jvn owns the respective file)

 

Where, the second jvn is known as Group Owner (Which means that the mentioned group i.e. jvn owns the respective file)


 

Permission Rule in Detail

 

d r w x r w x r w x

d - d for directory, 

- for file

 

  • rwx (First part) - Read, Write, and Execute permission for the user owner to the respective file/directory. 

  • rwx (Second part) - Read, Write, and Execute permission for the group owner to the respective file/directory. 

  • rwx(Third part) - Read, Write, and Execute permission for all users to the respective file/directory. 

 

Note: Users with Super User access can rewrite all rules. 

 

Permissions Break - Down Chart

 

Octal

Binary

File Mode

0

000

---

1

001

--x

2

010

-w-

3

011

-wx

4

100

r--

5

101

r-x

6

110

rw-

7

111

rwx


 

The command to Change Owner of file/directory 

 

  1. Sudo Privileges

 

$ su 

switch to sudoer or simply use the command with sudo as below


 

  1. Change the owner of the file/directory

 

$ sudo chown some_user some_file/directory 

change owner to some_user

 

  1. Change the group of the file/directory 

 

$ sudo chgrp some_group some_file/directory 

change group to some_group

 

Change Permission of file/directory 

 

  1. Provide read and write access to owner only

 

$ chmod 600 some_file

 

  1. Provide read, write and execute access to owner and group only

 

$ chmod 770 some_file

 

  1. Only read access to owner, group and all

 

$ chmod 444 some_file

 

Similarly, other patterns can be created and assigned.