Linux File Permissions and Ownerships

Linux Files and File Permission, Understanding linux file permission, file permissions in linux, easy explaination of linux file permission, file permissions

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
root@selva:~/test# 
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:
[ads-post]
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
or
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 http://www.learnitguide.net/2015/11/special-file-permissions-setuid-setgid-stickybit.html

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?
just type umask and you will get the default UMASK

How to convert the 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 the 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
or
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
or
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.

Thanks for reading our post. share with your friends. We appreciate your feedback, Leave your comments if any.

We have more articles to be updated soon. To not miss any updates, Follow us on social networking sites and Subscribe us on our Youtube channel.
November 29, 2015

Post a Comment

[disqus][facebook][blogger]

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget