File permissions in Linux [with infographics]

The Linux/Unix systems are multi-user systems and each file and directory has its own permission. This is in fact can be related to the origin of Unix which was conceived as a network system with multi users simultaneously working in the same environment. In that case, it is important to distinguish each file and directory's access rights to keep it secure. It is important to control which user has the right to modify or delete any file or directory.

Check file permission symbols


Run the command ls -l and you will the list of files and directories like below:

-rw-r--r--  1  ambarish  users  1201  Dec 12  13:10 info.txt

This basically represents that the file info.txt was created on Dec 12, at 13:10 and has a size of 1201 bytes. It belongs to the group "users" and is owned by the user "ambarish" in particular.

-rw-r--r--, drw-r--r-- basically represents the file permission.

1 - denotes the file type. a hyphen (-) denotes a regular file. "d" denotes a directory.
2,3,4 denotes read, write, execute permissions for the owner of file.
5,6,7 denotes read, write, execute permissions for members of group owning the file.
8,9,0 denoted read, write, execute permissions for all other users.

How to set permission of a file/directory


We can use chmod command in Linux to set permission of a file or a directory. They syntax is

chmod [permissions] [filename]

The permission can be assigned to any file or directory using the octal number system. 4 represents read access, 2 for write and 1 is for the access to execute.

So, if you want to assign a file read / write / execute access, it will be 4+2+1=7.

e.g.    chmod 777 info.txt 

will change the file access rights such that owner, group, and others and read, write and execute the file. You have to work out with the numbers.

7 = 4+2+1 - read, write, execute
6 = 4+2 - read write
5 = 4+1 - read execute
4 - read
3 = 2 + 1 write, execute
2 - write
1 - execute

Here's an infographic showing the file permissions in Linux/Unix.

File permissions in Linux infographics

Source: itsfoss.com

Anything I missed? Please add it in the comments section.

0 komentar:

Posting Komentar