140 likes | 357 Views
Permissions. OS515 (Workbook 4). Viewing Permissions. To view permissions from the command line use ls -l . [ student@station student]$ ls -l / var /gigs/ total 28 - rw - rw -r-- 1 elvis elvis 129 Jan 13 14:48 atlanta - rw -r--r-- 1 blondie music 142 Jan 13 14:46 boston
E N D
Permissions OS515 (Workbook 4)
Viewing Permissions • To view permissions from the command line use ls -l [student@station student]$ ls -l /var/gigs/ total 28 -rw-rw-r-- 1 elviselvis 129 Jan 13 14:48 atlanta -rw-r--r-- 1 blondie music 142 Jan 13 14:46 boston -rw-rw-r-- 1 elvis music 143 Jan 13 14:48 chicago -rwxr-x--- 1 root music 55 Jan 13 15:25 generate_report.sh -rw-rw-r-- 1 root music 2057 Jan 13 14:47 los_angeles -rw-rw-r-- 1 elvis music 142 Jan 13 14:47 san_francisco -rw-rw-r-- 1 blondieblondie 135 Jan 13 14:47 springfield
Permissions [student@station student]$ ls -l /var/gigs/ total 28 -rw-rw-r-- 1 elviselvis 129 Jan 13 14:48 atlanta -rw-r--r-- 1 blondie music 142 Jan 13 14:46 boston
Changing File Permissions: chmod • The chmod command is used to modify file permissions • The first argument to chmod uses a {ugoa}[+-=]{rwx}syntax to describe how the permissions should be changed chmodg+wfilename chmodg-w filename chmodg-w,o+rfilename chmod–R u=rw,g=r,o= directory/
Chgrp and chown • To change the owner of a file use chown chown new-owner file chown –R new-owner directory/ • To change the group of a file use chgrp chgrpnew-group file chgrp–R new-groupdirectory/
Who can chown or chgrp? • Only the root user can use chown • A user can chgrp a file if they are a member of the group they wish to change the file to rpw@ux01:~$ touch secret.plan rpw@ux01:~$ chmod u=rw,g=r,o= secret.plan rpw@ux01:~$ ls -l secret.plan -rw-r----- 1 rpwrpw 0 2010-05-17 17:19 secret.plan rpw@ux01:~$ chgrp admin secret.plan rpw@ux01:~$ ls -l secret.plan -rw-r----- 1 rpw admin 0 2010-05-17 17:19 secret.plan
chmod Revisited: Octal Notation • The chmod command can use an alternate octal syntax • The octal syntax is often quicker and more exacting chmodog-r diary chmodu=rw,g=r,o= diary chmod 600 diary
Where did 600 come from? 755 = rwxr-xr-x(u)ser = rwx= 4 + 2 + 1 = 7(g)roup = r-x = 4 + 0 + 1 = 5(o)ther = r-x = 4 + 0 + 1 = 5640 = rw-r-----(u)ser = rw- = 4 + 2 + 0 = 6(g)roup=r-- = 4 + 0 + 0 = 4(o)ther=--- = 0 + 0 + 0 = 0701 = rwx-----x(u)ser = rwx = 4 + 2 + 1 = 7(g)roup=--- = 0 + 0 + 0 = 0(o)ther=--x = 0 + 0 + 1 = 1
Controlling default permissions: umask • Linux creates files with a default mode of 666 (rw-rw-rw) • Linux creates directories with a default mode of 777 (rwxrwxrwx) • Every process possesses a "umask" parameter which masks out certain of these default permissions • In Red Hat Enterprise Linux, the default umask for standard users is 002 • The bash shell's umask is modified with the umask command.
file umask examples kernel default: 666 --> rw-rw-rw- umask: 002 --> -------w- default permissions: 664 --> rw-rw-r-- kernel default: 666 --> rw-rw-rw- umask: 077 --> ---rwxrwxdefault permissions: 600 --> rw-------
directory umask examples kernel default: 777 --> rwxrwxrwxumask: 002 --> -------w- default permissions: 775 --> rwxrwxr-x kernel default: 777 --> rwxrwxrwxumask: 077 --> ---rwxrwxdefault permissions: 700 --> rwx------