chmod and umask

Follow me for more content or contact for work opportunities:
Twitter / LinkedIn

Both UNIX commands are used to set permissions, chmod is for changing permissions of a specific file, and umask is for setting default creation permissions for a user.

Basics
Simple UNIX permissions are:
r (read)
w (write)
x (execute)
and them can be assigned to users:
u (user/owner)
g (group)
o (others)
a (all/last 3)

Easy chmod:
chmod

+ (add permissions)
chmod

- (remove permissions)Examples:
chmod a+r myfile (everybody can read)
chmod o-w myfile (only owner and users in group can write)

"Difficult" chmod:
Use numbers for setting permissions. 3 digits, first for owner, second for group and third for others.
To calculate a number you have to sum next values: 4 for read, 2 for write, 1 for execute.

Example:
Want to add read and write for owner, just read for group, and nothing for others...
1st: 4 (read) + 2 (write) = 6
2nd: 4 (read) = 4
3rd: 0
chmod 640 myfile

umask
umask value is calculated in next way; maximum permissions less chmod desired value.
If we want 750 permissions (rwxr-x---):
0777
-0750
------
0027

so add...
umask 0025
to
~/.bashrc

Follow me for more content or contact for work opportunities:
Twitter / LinkedIn