Tuesday, August 12, 2014

File Permissions in Linux - Umask,Chmod,Chown.

9:13 AM



File permissions

Linux uses the same permissions scheme as Unix. Each file and directory on your system is assigned access rights for the owner of the file, the members of a group of related users, and everybody else. Rights can be assigned to read a file, to write a file, and to execute a file.
Permissions on Unix systems are managed in three distinct scopes or classes. These scopes are known as user(U), group(G), and others(O).


Values for Read, Write and Execute.
Read        - 4
Write       - 2
Execute   - 1

  • The read permission grants the ability to read a file. When set for a directory, this permission grants the ability to read the names of files in the directory, but not to find out any further information about them such as contents, file type, size, ownership, permissions.
  • The write permission grants the ability to modify a file. When set for a directory, this permission grants the ability to modify entries in the directory. This includes creating files, deleting files, and renaming files.
  • The execute permission grants the ability to execute a file. This permission must be set for executable programs, including shell scripts, in order to allow the operating system to run them. When set for a directory, this permission grants the ability to access file contents and meta-information if its name is known, but not list files inside the directory, unless read is set also.
           
Symbolic Way
Numeric Way
Permission
User (U)
Group(G)
Others(O)
---                 ---                   ---
000
No Permission
--x                --x                  --x
111
Execute
-w-               -w-                 -w-
222
Write
-wx               -wx                -wx
333
Write & Execute
r--                 r--                   r--
444
Read
r-x                r-x                  r-x
555
Read & Execute
rw-               rw-                 rw-
666
Read & Write
rwx              rwx                rwx
777
Read & Write & Execute






To see the permission settings for a file, we can use the ls command as follows:

root@linuxstorages:~# ls A1.html
-rw-r--r--   1 root root  353 Aug 25 18:13 A1.html

Here file A1.html has the permission 644. Users have read & write, group and others have only read permission.

CHMOD 

Chmod command is used to set permission for the files and folders.

Eg: Numeric way of assigning permission to a file.

root@linuxstorages:~# chmod 640 ab.txt  

root@linuxstorages:~# chmod 666 ac.txt

root@linuxstorages:~# chmod 755 ad.txt

Eg: Symbolic way of assigning permission to a file.

root@linuxstorages:~#chmod  ugo+x  ab.txt

Adding execution permission to all user, group and others.

root@linuxstorages:~# chmod u=w,g=wx,o=x dd.txt

user – write, group – write and execute, others – execute.

root@linuxstorages:~# chmod u-wx,g-x,o-rw ac.txt

Removing write and execute from user, execute from group , read and write from others.

What is UMASK ?

The user file creation mode mask [umask] is used to determine the file permission for Normal and Root user.

Default value for Folder  777

Default value for File      666

For Root user Umask value is 022

Type
Permission
Umask
Subtract
Folder
Permission
Folder
777
022
777-022
755
rwxr-xr-x
File
666
022
666-022
644
rw-r--r--

For Normal user Umask value is 002

Type
Permission
Umask
Subtract
Folder
Permission
Folder
777
002
777-002
775
rwxrwxr-x
File
666
002
666-002
664
rw-rw-r--

To understand the value of default UMASK value for Root and Normal user.


root@linuxstorages:~# vi /etc/bashrc


CHOWN


Changing the user ownership of a file or a directory.

root@linuxstorages:~# chown <User Name> <File Name>

root@linuxstorages:~#chown storage sample.txt

-R option is used for recursive mainly for directories and have sub-directories.

root@linuxstorages:~#chown –R storages /home/backup

Permission will reflect to all it sub-directories in backup folder.


CHGRP

To change a group for a file or a folder.


root@linuxstorages:~# chgrp storages abc.txt

root@linuxstorages:~# chgrp storages /data

will change only to data folder.

root@linuxstorages:~#chgrp –R storages /data

will change all its sub directories in data folder.


Written by

0 comments :

Post a Comment

 

© 2014 Linux Storages | Updated . All rights resevered. Designed by Templateism