You can Watch all our Tutorials and Training Videos for Free on ourYouTube Channel

Linux File Permissions & Ownerships - Everybody Should Know

linux file permissions, understanding linux file permission, file permissions in linux, linux file permissions explained, linux file permission

Linux File Permissions and Ownerships

This post will help you to understand about Linux File Permissions and Ownerships.

If you are interested in learning, Request you to go through the below recommended tutorial.

Linux File Permissions and Ownerships

In Linux, There are three general classes of users:

User (u) - The user who owns the file.
Group (g) - Users belonging to the file's defined ownership group.
Others (o) - Everyone else.

In turn, for each of these classes of user, there are three types of file access with values:

Read (r) - 4
Write (w) - 2
Execute (x) - 1

For example, when you list the contents of a directory at the command line using the ls command as follows:
root@selva:~/test# ls -l
total 0
-rwxr-xr-- 1 selva dba 0 Nov 29 14:10 file1

You will see that you now get lots of details about the contents of your directory, similar to the example above.

With respect to Linux file permissions and Ownership, We need to consider the First, Third and Fourth Column of the file or folders.

First Column represents the file permissions.
Third Column represents the Owner name of the file or folder.
Fourth Column represents the Group name of the file or folder.

First Column represents the File Permissions

There are ten symbols here. The first dash ("-") means that this is a "regular" file, in other words, not a directory (or a device, or any other special kind of file). The remaining nine symbols represent the permissions: rwxr-xr--. These nine symbols are actually three sets of three symbols each, and represent the respective specific permissions, from left to right:

rwx     - The file owner "selva" can read, write and Execute this file.
r-x      - Anyone in the group "dba" can read and execute this file, but no write access.
r--       -  Any other users can read this file, but no write or execute access.
In short, We can also represent the permissions rwx as number "7" (read=4, Write=2, execute=1), so we had the file permission of the file1 as below.

rwx   - 7 - Permission for the owner
r-x    - 5 - Permission for the Group
r--      - 1 - Permission for the others

So we can specify it as 754.

When user create a file or directory under Linux or UNIX, File permissions are set as per the UMASK Value. It can be used to control the default file permission for new files. It is a four-digit octal number 0022. This can be set or expressed using:

Symbolic values (Example rwx)
Octal values (Example 421)

How to set or change default UMASK for all the new users?

The UMASK value can be set in /etc/profile for all the new users. Open this file as root user and write below line in the file.

umask 044
umask 0044

As we said earlier, umask has four digit octal number explained below. There is no difference between these two, both indicates one and the same. The preceding 0 indicates there is no SUID/SGID/Sticky bit information set. Also to know more about Special permissions in linux, read here
First Value (0) - To set the permission SetUID, SetGID , Sticky Bit
Second Value (0) - To set the owner permissions
Third Value (4) - To set the group permissions
Fourth Value (4) - To set the Permissions for everyone.

How to see default UMASK value?

just type umask and you will get the default UMASK

How to convert UMASK Value into file permissions?

If umask value is 022, then substract the full permission (777) from the UMASK Value (022), so the permission of newly created file would be 755. That is (7- rwx for Owners, 5 - r-x for groups and 5 - r-x for others)

How to change file permissions in linux?

We can the change/modify the file permissions of files or folders using the command "chmod" with either Symbolic values (Example rwx) or Octal values (Example 421) as below.
chmod u+rwx,g+rx,o+rx file1
chmod 755 file1

Above both commands are same to set the permissions as,

Read,Write,Execute for the owner
Read and Execute for the group
Read and Execute for the others

Example : Set a full permission for owner and read permission for group and others which means remove all other permissions of the file1.
chmod u+rwx,g+r,g-wx,o+r,o-wx file1
chmod 744 file1

How to change/modify owner name and group name

Use the chown command to modify the owner and group name of the file or folder as below.

Example : Lets take the below ls -l output.
root@selva:~/test# ls -l
total 0
-rwxr-xr-- 1 selva dba 0 Nov 29 14:10 file1

Change the owner name of the file from selva to karthik and group name from dba to admin. Finally check the ls -l output.
root@selva:~/test# chown karthik:admin file1
root@selva:~/test# ls -l
total 0
-rwxr-xr-- 1 karthik admin 0 Nov 29 14:10 file1

Thats all about linux basic default file permissions and ownership. Hope this post helped you to understand Linux File Permissions and Ownerships with examples.

Keep practicing and have fun. Leave your comments if any.

Support Us: Share with your friends and groups.

Stay connected with us on social networking sites, Thank you.

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.
whatsapp logo