What Are Linux Permissions?
Permissions are fundamental to linux security, they govern who (or what) can access certain files as well as what they can do with them. File permissions in linux are designed to be simple, however, this simplicity can cause issues when misconfigured or neglected altogether.
Which Kind of Linux Permissions do we Have?
In Linux we have three basic permissions, they are;
read (r): 4
Read Permissions let us access a file's contents i.e. we can view a file that has read permissionswrite (w): 2
Write permissions allow us to modify the contents of a file as well as carry out other functions such as copying, moving or creating a file in a directoryexecute (x): 1
Execute permissions let us run a particular file. Some examples would be bash scripts, executable files, etc...
Note that I've put numbers beside each type of permission, these are the octal values for each permission. Personally I prefer to use the octal system when assigning permissions as i find it to be a bit quicker.
How Do we Interpret Permissions?
In the directory of our choice. We simply use
ls -l
This command does a long listing of all of the files in our directory
Let's interpret the image above. We have different components that are helpful for getting permissions information from our long listing. They include
- File Type:
- - Permission Settings:
---------or as per our imagerw-r--r-- - User Owner:
frank - Group Owner:
frank
For reference, full permissions would give us rwxrwxrwx. the first rwx are the permissions for a user, the second rwx are the permissions for a group and the third rwx are the permissions for others.
Octal Values
Linux file permissions can be represented by numbers. These numbers are as per the octal system (0-8)
Let's take an example where a permission of 764 is granted to a file
7 - This represents the user and the user can read, write and execute a file. 4(read) + 2(write) + 1(execute)
6 - This represents the group and the user can read and write the file. 4(read) + 2(write)
4 - This represents others - others in this case can only read the file. 4(read)
How to Modify Linux File Permissions
To modify file and directory permissions we can use the chmod command. chmod stands for "change mode".
Change mode can be used in either numeric mode or symbolic mode.
To do so, we enter chmod and then a class of user e.g u,g,o i.e. user,group,others.
For Example (Symbolic Mode):
$ chmod o+r dockerfile
$ chmod ug+rw dockerfile
For Example (Numeric Mode):
$ chmod 755 dockerfile
$ chmod 644 dockerfile
Note that in numeric mode we can also apply a permission recursively to an entire directory, for example:
chmod -R 755 /var/www/html
Conclusion
Linux permissions are a critical part of system security and file management. By understanding the three core permissions β read, write, and execute β and how they apply to users, groups, and others, we can confidently control access to our files and directories. Whether we prefer symbolic or numeric (octal) mode, the chmod command gives us the flexibility to set permissions quickly and precisely. Getting comfortable with permissions is an essential step toward becoming proficient in Linux.

Top comments (0)