Tuesday, August 24, 2010

Basic file permitions

*The linux file has 8 attributes which are listed with (ls -l or ll) commands.
-rw-r--r--1 root root 1230 Feb 12 15:20 raj.doc

1st field

Types

- files
d directories
l links
p processfile
s socket files
b block devices
c character devices

2nd field.
rwx  owner

3rd field.
rwx group

4th field.
rwx others

Ex.  -     rwx    rwx    rwx   1 root root 1230 Feb 12 15:20 raj.doc
   (type)(owner)(group)(others)


Permition access mode.

             File                              Directory

r --> To display contents of a file.      To list contents of a dir.(Read only)

w --> To create or append a file.         To create file’s & directories.(Read & Write)

x --> To execute a file.                  To execute to a directory.


File Permition Mode.

Permitions
1) Symbolic mode -- rwx
2) Absolute mode -- 421

*Defoults file permition.

1) When a file created with the help of cat, touch, vi will get the permissions as 644.
EX.-->  - rw- r-- r--

2)Actually in the basic UNIX system when a file is created it gets the permission as 666.

3)But this lapses in security, so when ever a file is created in UNIX system it masks some
  bits,with a mask value of 022.

4)After masking we get the default value of a file as
  644. [666 – 022 = 644]

5) 022 is as the UMASK value.



*Default directory permitions.

1)When a directory is created with the help of mkdir will get the permissions as 755.
  d rwx r-x r-x


2)Actually in the basic UNIX system when a directory is created it gets the permission as 777.
  But this lapses in security,so whenever a directory is created in UNIX system it masks some
  bits,with a mask value of 022.


3)After masking we get the default value of a file as
  777. [777 – 022 = 755]

4)022 is as the UMASK value.


###############################################################

1)To view the umask value.
#umask

2)To view the umask value into file.
#vim /etc/bashrc

3)To create file.
#touch 123
#ll 123
-rw-r--r-- 1 root root 0 Feb 12 08:18 123
 (6  4  4) After umask value.

4)To create Directory
#mkdir ram
#ll
drwxr-xr-x 2 root root  4096 Feb 12 08:21 ram
 (7  5  5) After umask value.

##############################################################


chmod Command

1)chmod command is used to change the permissions of a file/directory.

2)chmod can be used by the owner of the file or by root.

3)With chmod command we can assign permission’s or remove permissions as required.

4)Permission parameters used with chmod command

Category    u g o
Operators   + - =
Permissions r w x
Weight      4 2 1

Applying permission to Owner (u), Group (g) & Others (o) for File1

Applying permission to File or Directory

#chmod (permitions) (file/derectory)

################################################################

*Example of Permission - Absolute.

#touch 123
#ll
-rw-r--r-- 1 root root     0 Feb 12 08:18 123

*To change the value.

#chmod 777 123
-rwxrwxrwx 1 root root     0 Feb 12 08:18 123

#chmod 766 123
#ll
-rw-rwxrwx 1 root root     0 Feb 12 08:18 123

##############################################################

*Example of Permission - Symbolic

#touch text
-rw-r--r-- 1 root root     0 Feb 12 08:31 text

1)change group permition.(+)
#chmod g+w text
-rw-rw-r-- 1 root root     0 Feb 12 08:31 text

2)change user permition.(-)
#chmod u-w text
-r--rw-r-- 1 root root     0 Feb 12 08:31 text

3)change others permition.(=)
before.
-r--rw-r-- 1 root root     0 Feb 12 08:31 text
After = permition.
#chmod o=rx text
-r--rw-r-x 1 root root     0 Feb 12 08:31 text