Tuesday, July 29, 2008

Linux File System Permission

It is divided into 4 parts

class:owner:group:everyone/other


Maximum Possible Permission bit

read(r) 4
write(w) 2
execute(1) 1

For eg:

[root@localhost ~]# ls -l install.log
-rw-r--r-- 1 root root 37356 2008-07-27 02:26 install.log
-42-4--4--

So this file has a permission 644

Maximum permission to any file 666

Maximum permission to any directory 777

By default if we create any file it has permission 644

By default if we create any directory it has permission 755

This is due umask value

[root@localhost ~]# umask
0022

For file 666 - 022 = 644
For directory 777 - 022 = 755

chmod: Alter the permission of files and directories

[root@localhost ~]# ls -ld abc
drwxr-xr-x 2 root root 4096 2008-07-29 12:01 abc

If we want to change the permission of this directory from default 755 to other we need chmod command

[root@localhost ~]# chmod 777 abc
[root@localhost ~]# ls -ld abc
drwxrwxrwx 2 root root 4096 2008-07-29 12:01 abc
[root@localhost ~]#

If we want this permission applied to all the create file inside this directory

-R, --recursive change files and directories recursively

chown - change file owner and group

[root@localhost ~]# chown prashant:prashant abc
[root@localhost ~]# ls -ld abc
drwxrwxrwx 2 prashant prashant 4096 2008-07-29 12:01 abc

-R, --recursive operate on files and directories recursively

chgrp - change group ownership

[root@localhost ~]# chgrp prashant abc1
[root@localhost ~]# ls -ld abc1
drwxr-xr-x 2 root prashant 4096 2008-07-29 12:09 abc1

SETGID Permission

[root@localhost ~]# mkdir share
[root@localhost ~]# chown root:prashant share/
[root@localhost ~]# ls -ld share
drwxr-xr-x 2 root prashant 4096 2008-07-29 12:14 share
[root@localhost ~]# chmod 2775 share/

Here we are assiging set group ID (2) or we do it like this (chmod g+s share)

[root@localhost ~]# ls -ld share
drwxrwsr-x 2 root prashant 4096 2008-07-29 12:14 share
[root@localhost ~]# ls -ld share
drwxrwsr-x 2 root prashant 4096 2008-07-29 12:14 share
[root@localhost ~]# chmod 777 share/

After doing this if any user try to create any file it has got the group prashant associated with it

[oracle@localhost share]$ ls -l
-rw-r--r-- 1 oracle prashant 0 2008-07-29 12:16 b

Symbolic Link(Soft and Hard Link)

Soft Link

ln [--option] [actual file] [name of symbolic link]

[root@localhost bash]# ln -s file1 symlink1

lrwxrwxrwx 1 root root 5 2008-07-29 12:22 symlink1 -> file1

All the permission bit are turn on in case of symbolic link to drill down the file

Note: We can create multiple symbolic link to the same file.But if the main file is removed then symboli link has no meaning.

[root@localhost bash]# ln -s file1 symlink2

lrwxrwxrwx 1 root root 5 2008-07-29 12:24 symlink2 -> file1

Both the symbolic link created have different inode number

159984 lrwxrwxrwx 1 root root 5 2008-07-29 12:22 symlink1 -> file1
159990 lrwxrwxrwx 1 root root 5 2008-07-29 12:24 symlink2 -> file1

Inode number: File stored in disk have unique number called inode number

Hardlink:

ln [actual file] [hardlink]

[root@localhost bash]# ln file1 hardlink1

159965 -rw-r--r-- 2 root root 0 2008-07-29 12:22 hardlink1
159965 -rw-r--r-- 2 root root 0 2008-07-29 12:22 file1

Both have same inode number

If we delete orignal file hardlink file exist.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home