File Permissions In Linux
- Just like every operating system, Linux comes with a set of permissions that it uses to protect files, directories, and devices on the system.
- These permissions can be manipulated to allow (or) disallow access to files and directories on different parts of the system.
Basic file permissions
Let’s look at how permissions work first. Linux permissions are implemented through the properties of files and are defined by three separate categories.
User: The person who owns the file.
Group: The group that owns the file.
Other: All other users on the system.
Permissions in Linux can be assigned one of two ways. You can use the mnemonic or a single digit to represent the permission level.
Operation | Digit | Mnemonic | Description |
Read | r | 4 | View file contents. |
Write | w | 2 | Write to me or change. |
Execute | x | 1 | Run the file. |
Default file permissions
Umask: Universal mask is a default value that always gets dedicated from maximum file permission allocated for every file & directory.
For super user umask value is # 022.
For Normal user, the umask value is $002
For superuser:
Maximum permission of a file 666-Umask (-)022
Default file permission ------> 644
Maximum permission of a directory 777-Umask (-)022
Default directory permission 755
Inclined to build a profession as Linux Developer? Then here is the blog post on, explore Linux Training
For Normal user:
Maximum permission of a file ---- 666----Umask (-)_002---664
Maximum permission of a directory---777 umask---002 (-)775
To see the umask # umask
To change the umask # umask 222
To view umask value from the fiel # vim /etc/ bashrc
Operators:
+ --->To add a permission.
- --->To remove permission.
= --->To override the permission.
Here are some of the commands you can use to work with permissions:
Chmod:- It is used to change the permission of a file and directory. It can be used by the owner of the file (or) by root.
Syn: Chmod [options] [permission] [file]
R ---> Acts recursively.
V ---> Provides verbose output.
Ex:
1) # Chmod u+rw,g+r, o+x linux # Chmod 641 linux
2) #chmod ugo =rw backup (or) # chmod 666 backup
3) #chmod U-W, g-r, o-x linux
4) #chmod-R U+W, g+r, o+x linux
5) #chmod-R 777 unix
6) # chmod 755 Unix
Chgrp: à By using this command we can change the group of the file.
Syn: Chgrp [options] [group name] [file]
R ---> Recursively
V ---> Verbose
Ex: #ls-l linux #chgrp sales linux
Chown: This command is used so we can change the owner of the file, as well as owner & group at a time.
Syn: Chown [options] [user:group] [file]
R---> Recursively
V---> Verbose.
Ex:
#Chown Raju Linux To Change the only owner.
#Chown Raju: sales Linux To Change owner & group
#Chown –R Ramu: color Unix Recursively to change.
To view the symbolic as well as a numeric mode of permission
# stat Linux
To change the permissions in GUI mode
#navtilus &
Assign the permissions in GUI mode:
Right-click on file ----->properties---->permissions.
For an in-depth understanding of Linux click on