1) Permissions : Read, Write & Execute
Read (r) : 4
Write (w) : 2
Execute (x) : 1 --> If this is on directory then user can go inside folder and list and if on script file then user can run script.
Here "d" represents directory
2) Mukesh user went to /tmp and created dir "mukesh"
[mukesh@RedHat mukesh]$ ls -ld /tmp/mukesh
d rwx rwx r-x. 2 mukesh mukesh 24 Jan 20 12:16 /tmp/mukesh
[mukesh@RedHat mukesh]$ ls -ld /tmp/mukesh/mukeshlife
-rw -rw- r--. 1 mukesh mukesh 0 Jan 20 12:16 /tmp/mukesh/mukeshlife
Now user adminji can read file mukeshlife but can't modify it.
3) If user mukesh assign write permission to others then user "adminji" can modify file "mukeshlife"
[mukesh@RedHat mukesh]$ chmod o+w mukeshlife
4) Another way to provide permission
chmod o=rwx /tmp/mukesh
[mukesh@RedHat mukesh]$ ls -ld /tmp/mukesh
drwxrwxrwx. 2 mukesh mukesh 24 Jan 20 12:16 /tmp/mukesh
5) To add user to group
usermod -G Groupname user
Add or remove permission from group from directory
chmod g+w /devteam
chmod g-w /devteam
chmod g=--- /devteam
Now create a group
groupadd newgroup
now make this group owner of a directory
chgrp newgroup /tmp/mukesh
To change owner of directory
chown user directory
To change owner and groupowner in one command of a particular directory.
chown user:group directory
To change owner group and other permission in one command
chmod u=--- ,g=--- ,o=---
To provide same command to owner group and other
chmod ugo=rwx directory
chmod -x directory or chmod +x directory
Now use numeric method to give permission
chmod 755 directory / file
[mukesh@RedHat mukesh]$ ls -ld /tmp/mukesh
drwxrwxrwx. 2 mukesh mukesh 24 Jan 20 12:16 /tmp/mukesh
[mukesh@RedHat mukesh]$ chmod 700 /tmp/mukesh
[mukesh@RedHat mukesh]$ ls -ld /tmp/mukesh
drwx------. 2 mukesh mukesh 24 Jan 20 12:16 /tmp/mukesh
Now the permission of file mukeshlife inside folder mukesh hasn't changed.
[mukesh@RedHat mukesh]$ ls -l /tmp/mukesh/mukeshlife
-rw-rw-rw-. 1 mukesh mukesh 8 Jan 20 12:26 mukeshlife
Note : If we use "R" while changing permission on the directory then it will change permission of all files and folders inside this directory to of parent.
[mukesh@RedHat mukesh]$ chmod 700 -R /tmp/mukesh
[mukesh@RedHat mukesh]$ ls -ld /tmp/mukesh/mukeshlife
-rwx------. 1 mukesh mukesh 8 Jan 20 12:26 /tmp/mukesh/mukeshlife
[root@RedHat adminji]# groupadd monu
[root@RedHat adminji]# chgrp monu /tmp/mukesh
[mukesh@RedHat mukesh]$ ls -ld /tmp/mukesh *
-rwx------. 1 mukesh mukesh 8 Jan 20 12:26 mukeshlife
drwx------. 2 mukesh monu 24 Jan 20 12:16 /tmp/mukesh
[root@RedHat adminji]# chgrp monu -R /tmp/mukesh
[mukesh@RedHat mukesh]$ ls -ld /tmp/mukesh *
-rwx------. 1 mukesh monu 8 Jan 20 12:26 mukeshlife
drwx------. 2 mukesh monu 24 Jan 20 12:16 /tmp/mukesh
This change in permission on group or changing group owner doesn't work for new files added in directory.
Comments