Saturday 18 April 2015

Linux Manage file permissions and ownership



1)
Login as admin user
       su anusree

2)
Add new linux group named sale

       sudo groupadd sale

3)
Add new user s1 with home folder

      sudo useradd -m s1
      -m : create home folder

4)
Add another user s2 with home folder
      
      sudo useradd -m s2

5)
 Add the existing user s1 and s2 to the group sale
      
      sudo adduser s1 sale
      sudo adduser s2 sale
6)
Create a folder sale in /opt
      
      sudo mkdir sale

7)
Create a file named sale.txt in the folder /opt/sale
   
      sudo vim sale.txt

8)
Check the permissions, owner and group of the file sale.txt
     
       ls -l sale.txt
       -rw-r--r-- 1 root root 0 Apr 19 00:13 sale.txt
             |    |
             |    +----- group (root)
             +---------- user (root)

        here user is the root and group is root, here user have read and write     permission and user's in group root have only read permission, and other user's have read permission

9)
 I am going to change the group of the file sale.txt from root group to sale group

      sudo chown root :sale sale.txt
                         or
      sudo chown :sale  sale.txt

10)
I am going to give read and write permission to the user's in the group sale to access the file sale.txt

      sudo chmod g+rw sale.txt

11
 Now i am giong login as one of the user inthe group sale (eg: s1) and trying to read and write to the file sale.txt , and this should work because i already set the permission to read and write to the group sale
   
      su s1
     

12)
If you want to change the user (owner) of the file sale.txt from root to s1
       
      sudo chown s1:sale  sale.txt

13)
Check the owner or user of the file sale.txt 

      ls -l
      -rw-rw-r-- 1 s1 sale 41 Apr 18 22:59 sale.txt                               
             |    |
             |    +----- group (sale)
             +---------- user (s1)

1 comment:

  1. POSIX Access Control Lists on Linux
    http://www.vanemery.com/Linux/ACL/POSIX_ACL_on_Linux.html

    ReplyDelete