*Octal Values for Permissions:*
*r (read)* = `2^2 = 4`
*w (write)* = `2^1 = 2`
*x (execute/open)* = `2^0 = 1`
*Default File Permissions:*
`644` (Owner: Read/Write, Group: Read, Others: Read)
UMASK (User File Creation Mask)
Defines default permissions for new files and directories.
Default UMASK: `022`
*Example Calculation for UMASK:*
If `xyz` folder has permissions `rwxr-x--- (710)`, then:
`777 (Full permissions) - 710 (Folder permissions) = 067`
Set UMASK to `067`.
*Check UMASK:*
Command: `umask`
*Set UMASK Temporarily:*
Command: `umask 027`
This change applies only to the current terminal session.
*Set UMASK Permanently:*
Modify `/etc/bashrc` (for all users).
Modify `~/.bashrc` (for a specific user).
Command: `vim ~/.bashrc`
Add `umask 027` at the end of the file.
Group Ownership Inheritance
If `root` creates `/test`, both owner and group will be `root`.
If the group is changed to `sales`, `/test` belongs to the `sales` group.
But if `root` creates a new file inside `/test`, the group resets to `root`.
To prevent this, *SGID (Set Group ID) bit* is used.
*Set SGID Bit:*
Command: `chmod 2775 /test`
Command: `chmod g+s /test`
*Remove SGID Bit:*
Command: `chmod 00775 /test`
Command: `chmod g-s /test`
SUID (Super User ID Bit)
Allows a normal user to execute a file with root privileges.
Only applies to **binaries (commands in Linux) and files**.
*Find Files with SUID Bit:*
Command: `find / -perm 4755`
*Add SUID Bit (Not Recommended, Only for Experimentation):*
Command: `chmod 4755 /bin/passwd`
Command: `chmod u+s /bin/passwd`
*Remove SUID Bit:*
Command: `chmod u-s /bin/passwd`
Command: `chmod 00775 /bin/passwd`