Setting default permissions
Notes:
Every new file or directory that you create will have some set of default
permissions assigned to it. You can set what these permissions will be with
the umask command.
Notes on umask:
-
The umask command can be used to set default permissions for any new file
that is created; it will not reset the permissions for existing
files.
-
On the linux filesystem, files cannot be set executable by default.
-
Umask determines which permissions are NOT allowed; it is the opposite of
chmod. The command: umask 026 gives:
-
permissions for the user are 0 = 000 binary
-
read allowed, write allowed, execute allowed
-
permissions for the group are 2 = 010 binary
-
read allowed, write NOT allowed, execute allowed
-
permissions for others are 6 = 110 binary
-
read NOT allowed, write NOT allowed, execute allowed
-
If the umask is 026, a new directory will have permissions: rwxr-x--x
-
If the umask is 026, a new file will have permissions: rw-r-----
(the execute permissions are not turned on automatically)
Exercise:
-
What is your current umask value? (enter the command: umask)
-
Use the mkdir command to make a new directory. What are the permissions for
this directory? ____________________
-
Use the touch command to create a new file. What are the permissions for
this file? ____________________
-
Set the umask to 022.
-
Use the mkdir command to make a new directory. What are the permissions for
this directory? ____________________
-
Use the touch command to create a new file. What are the permissions for
this file? ____________________
-
Change your umask so that the default permissions for any directory that
you create are rwx------. What is the umask? ____________________
-
Create a new directory. Verify that the umask worked.
-
With this umask, what are the permissions for a new file? ____________________
Questions & Answers:
-
What command will change the permissions on the existing file readme to
rw-rw-r--?
Answer: chmod 664 readme
-
Assume that the "new" directory does not exist. The following commands are
executed:
umask 027 ; mkdir new
What are the permissions for the new directory?
Answer: rwxr-x---
-
Assume that "newfile" does not exist. The following commands are executed:
umask 027 ; touch newfile
What are the permissions for the new file?
Answer: rw-r-----
Copyright ©
L.M.MacEwan