Permissions and chmod
Last Update Unknown
Permissions and chmod
Permission Syntax
The "who" values we can use are:
- u: User, meaning the owner of the file.
- g: Group, meaning members of the group the file belongs to.
- o: Others, meaning people not governed by the u and g permissions.
- a: All, meaning all of the above.
The "what" values we can use are:
- -: Minus sign. Removes the permission.
- +: Plus sign. Grants the permission. The permission is added to the existing permissions. If you want to have this permission and only this permission set, use the = option, described below.
- =: Equals sign. Set a permission and remove others.
The "which" values we can use are:
- r: The read permission.
- w: The write permission.
- x: The execute permission.
For example, if I wanted the user dave to have read and write permissions and the group and other users to have read permissions only.
I would use the command:
Permission Numbers
One way to use chmod is to provide the permissions you wish to give to the owner, group, and others as a three-digit number.
0: (000) No permission.
1: (001) Execute permission.
2: (010) Write permission.
3: (011) Write and execute permissions.
4: (100) Read permission.
5: (101) Read and execute permissions.
6: (110) Read and write permissions.
7: (111) Read, write, and execute permissions.
For example, if I wanted to make it so that a user 'Jack' can read, write, and execute, group 'Admins' can read and execute, and 'Other' can write and execute.
I would use the command:
Umask
umask sets which permissions must be removed from the system default when you create a file or a directory.
For example, a umask of 6 would remove read and write permissions and leave you with execute only.
How to calculate umask values for files and directories?
Here, when we execute the command, the values are not directly allocated as 5 for the owner, 4 for the group members and 3 for the others, but the value we pass as an argument is subtracted from the max/full permission set.
There are two full permission sets:
- File -> The full permission set for a file is 666 (read/write permission for all)
- Directory -> The full permission set for a directory is 777 (read/write/execute)
What is the difference between chmod and umask?
The umask command can be only used on new files i.e. while creating new files, any files created prior to using the umask command will have no effect.
The chmod command must be used on files that are already present, it is used to change the access permissions of files that have been created earlier.
Permissions | Octal Value |
---|---|
— | 0 |
–x | 1 |
-w- | 2 |
-wx | 3 |
r– | 4 |
r-x | 5 |
rw- | 6 |
rwx | 7 |