150 likes | 461 Views
File ownership and permissions. File ownership. Every file in Linux must have the following:- File user owner File group owner File permissions There are 3 types of file permissions:- r - read w - write x - execute
E N D
File ownership • Every file in Linux must have the following:- • File user owner • File group owner • File permissions • There are 3 types of file permissions:- • r - read • w - write • x - execute • These file permissions are further grouped into the following categories:- • (u)ser owner • (g)roup owner • (o)thers
To view all the information discussed on the previous slide. We can use the ‘-l’ option of the ‘ls’ command. To modify file ownership and permissions, use the ‘chmod’, ‘chgrp’ or ‘chown’ command.
chmod Usage The ‘chmod’ is used to change file permissions. Every file has the following permission bits To change the permission of a file, we use the chmod command with the following options shown on the next slide.
Example chmod options chmodu+x<filename> chmod -w<filename> chmodug+w<filename> chmod all=x<filename> Where <filename> is the name of the file to change permissions on.
Changing file group and user owner To change a file’s group owner, we use the ‘chgrp’ command. Only the root user can change the user owner of a file. To change the user owner, use the ‘chown’ command.
Directory permissions Directories are treated in the same way as files. We use the same commands and options to change permissions and ownership. The only difference is the e(x)ecute bit. In directories, ii does not make sense to execute a directory. Rather, it is use by the kernel to permit access to the directory.
Octal notation for chmod command Each permission bit for the (u),(g) and (o) categories are given a value as shown below:- All octal notation need to have 3 digits to work. The value of the 3 digits are the sum of the activated permission bits of the 3 categories.
Example octal notation chmod 666 <filename> - means the file will have rw bits set for all the categories. chmod 777 <filename> - means the file will have all permission bits set for all categories. chmod 750 <filename> - means the file have all permissions set for owner, rx bits only for group, no permission bits set for others.
Umask Default permission for Linux files are 666. Default permission for Linux directories are 777. But when we logon, there is a special variable called umask. This umask controls the default permissions for file and directory creation. Default value for umask is 002. To change the umask value after logon. Use the umask command.
Understanding umask • Default kernel file permissions:- rw-rw-rw- means 666 umask 002 default file create permissions 664 • Default kernel directory permissions:- rwxrwxrwx means 777 umask 002 default dir create permissions 775