In Linux, the file permissions help to access, write, and execute the files. These permissions restrict the other users from performing an unauthorized activity, and thus they maintain security.
There are three principal permissions in Linux.
The read permission provides the capability to read/view the file's contents. We execute this permission with the letter r
.
The write permission provides the ability to modify the file, i.e., add or remove contents from the file. We execute this permission with the letter w
.
The execute authorization offers the ability to run the file. For example, you'll need this permission to run a shell script. The letter x
describes this permission.
The Linux permissions model has three user categories. Every user class has its reading, writing, and executing permissions set. Here're the three categories:
We use the ls
command to check the file permissions with an extension l
indicating the long list format. Here's a syntax and an example.
ls -l
root@educative:/# ls -ltotal 45drwxr-xr-x 1 root root 1024 Dec 31 2018 bindrwxr-xr-x 2 root root 1024 Apr 12 2016 bootdrwxr-xr-x 5 root root 340 May 11 20:18 devdrwxr-xr-x 1 root root 4096 May 11 20:18 etc-rw-r--r-- 1 root root 6 May 11 20:18 file.txtdrwxr-xr-x 2 root root 1024 Apr 12 2016 homedrwxr-xr-x 1 root root 1024 Dec 31 2018 libdrwxr-xr-x 2 root root 1024 Nov 13 2018 lib64drwxr-xr-x 2 root root 1024 Nov 13 2018 mediadrwxr-xr-x 2 root root 1024 Nov 13 2018 mnt-rw-r--r-- 1 root root 11488 Dec 31 2018 nodesource_setup.shdrwxr-xr-x 2 root root 1024 Nov 13 2018 optdr-xr-xr-x 122 root root 0 May 11 20:18 procdrwx------ 1 root root 4096 May 11 20:18 rootdrwxr-xr-x 1 root root 1024 Nov 13 2018 rundrwxr-xr-x 1 root root 1024 Dec 31 2018 sbindrwxr-xr-x 2 root root 1024 Nov 13 2018 srvdr-xr-xr-x 13 root root 0 May 11 20:18 sysdrwxrwxrwt 1 root root 4096 May 11 20:18 tmpdrwxrwxrwx 2 root root 4096 May 11 20:18 usercodedrwxr-xr-x 1 root root 1024 Nov 13 2018 usrdrwxr-xr-x 1 root root 1024 Nov 13 2018 var
The ls -l
command returned us information about 45 contents within the directory. The first column in the results indicates the permissions for the owner, group, and other categories.
-rw-r–-r-- 1 root root 6 May 11 20:18 file.txt
-
indicates that this is a file.rw-
indicate that the owner can read and write the file.r--
indicate that the group members only have read permission.r--
indicate that the other members will only have read permission.