Lab 7: File and Directory permissions

Lab 7: File and Directory permissions

Some useful commands:

#To change user ownership of directory
chown john /home/john     

#To change permission level of directory
chmod 700 /home/john    

#To change permission level of directory and subdirectories recursively 
chmod –R (permission level)     

#Show current umask
umask      

#Change umask                
umask 077  

Example of changing permissions using alphabetical method:

#Assign write permission to others and deny read permission to group category
chmod o+w,g-r /data 

Sticky-bit commands:

#Apply sticky-bit to /data directory
chmod 1777 /data      

#Apply sticky-bit to /data directory 
chmod  +t /data             

#Remove sticky-bit from /data directory 
chmod -t /data  

Change ownership of file/directory

chown ajay /abc.txt

Change group ownership of file/directory

chgrp accounts /data

Change both user ownership and group ownership of file/directory

chown ajay.accounts /data

Change ownership of directories recursively

chown -R ajay.accounts /data

Change permissions of a directory recursively

chmod 770 /data -R

File Access Lists

#To set FACL for a user on a file/directory
setfacl –m u:jane:rwx /fileordirectory

#To set FACL for a user on a file/directory
setfacl –m g:sales:rwx /fileordirectory

#To check FACL for a file/directory
getfacl /fileordirectory

#To remove a particular FACL policy
setfacl –x u:jane /fileordirectory

#To remove entire FACL from file/directory
setfacl  -b /fileordirectory