Unix file and directory permission is in the form of a 3×3 structure. i.e Three permissions (read, write and execute) available for three types of users (owner, groups and others).
In the output of ls -l command, the 9 characters from 2nd to 10th position represents the permissions for the 3 types of users.
-rw-r--r-- 1 sathiya sathiya 272 Mar 17 08:22 test.txt
In the above example:
- User (sathiya) has read and write permission
- Group has read permission
- Others have read permission
Three file permissions:
- read: permitted to read the contents of file.
- write: permitted to write to the file.
- execute: permitted to execute the file as a program/script.
Three directory permissions:
- read: permitted to read the contents of directory ( view files and sub-directories in that directory ).
- write: permitted to write in to the directory. ( create files and sub-directories in that directory )
- execute: permitted to enter into that directory.
Numeric values for the read, write and execute permissions:
- read 4
- write 2
- execute 1
To have combination of permissions, add required numbers. For example, for read and write permission, it is 4+2 = 6.
Change File and Directory Permissions Using Chmod Command
You can use either the octal representation or symbolic representation to change the permission of a file or directory.
Octal representation for permissions:
- First number is for user
- Second number is for group
- Third number is for others
For example, give read, write ( 4+2 = 6 ) to user and read ( 4 ) to group and others.
$ chmod 644 filename
For example, give read, execute ( 4 + 1 = 5 ) to user and read (4 ) to group, and nothing ( 0 ) to others.
$ chmod 540 filename
For example, give read, write ( 4 + 2 = 6 ) to user and nothing ( 0 ) to group, and read ( 4 ) to others.
$ chmod 604 filename
Umask 022 is Responsible for the default permission of a file
The default umask value is 0022, which decides the default permission for a new file or directory. Default permission for a directory is 0777, for files the permissions are 0666 from which the default umask value 0022 is deducted to get the newly created files or directory permission.
Final default permission for a file is calculated as shown below:
- Default file permission: 666
- Default umask : 022
- Final default file permission: 644
Final default permission for a directory is calculated as shown below:
- Default directory permission: 777
- Default umask: 022
- Final default directory permission: 755
You can change the umask value to appropriate value of what you need based upon the above calculation. For example, if you don’t want anybody other than the user (owner) to do anything on the file or directory then you can give umask as 0077.
$ umask 0077
After this, if you create a file or directory, it will have permissions only for the user as shown below:
$ > testfile $ ls -l testfile -rw------- 1 sathiya sathiya 0 Mar 17 08:23 testfile
Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you don’t know what these tools are and how to use them, you could be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help you understand system administration tools, which will help you to become an effective Linux system administrator.Get the Linux Sysadmin Course Now!
If you enjoyed this article, you might also like..
|
|
|
|






My name is Ramesh Natarajan. I will be posting instruction guides, how-to, troubleshooting tips and tricks on Linux, database, hardware, security and web. My focus is to write articles that will either teach you or help you resolve a problem. Read more about
{ 11 comments… read them below or add one }
Hi! Thanks for the clear explanation on using umask
thanks …. i m learning some thing atleast ..in easy steps ..and clearly..
Really Superb.Thanks for sharing with us.The best part of your writing is the examples. Could you provide documentation on configuring LDAP which I badly need.No step by step guide are available in net.
hi…nice article…..
i want to know can we change the default permission of a directory “777″……
i am just wondering what will happen if let say default permission is 755 and then we set umask as 666 what will then be the final default permission ?
HI , Brilliant notes. Hope you contunue to enrich our knowledge
sorry for being the dumb one here, but is there a way to add execute to file permissions? I know you can, but the assignment is asking to add them with umask.
Say the default is rw-rw-rw- for files, I am being asked to use umask to make the following..
THANK U SO MCH
Good basic article
Hi,
I have a doubt. Let’s say i dont have write permission for a folder “xyz”.
I have an application running that will try to write a file to this folder.
So now, WIll it thrown any exception or it will write to tmp space?
Please help me with this question.
Thanks in advance,
Naveen.
thanks! this article explained in one page better than what a load of other articles have failed to explain in 10
Hi,
It’s really a nice post and very much helpful for beginer like me. Thanks a lot!!