| Understanding Linux Security: Users, Groups, and Permissions |
|
by nature Linux is a muti-user system three types of users
|
| Reading Permission Notation: rwx and Numeric Representation |
|
the command ls -l produces the detailed list about a folder's contents lines are similar to -rwxr-xr-- 1 n4jvp n4jvp 4096 Jan 27 10:00 script.shthe first 10 characters provides permission data File Types
the first character provides the object type
Permission Triplets
remaining 9 characters are three sets of three
rwx r-x r--
What Do the Letters Mean
|
| The Three Permission Sets: Owner, Group, and Others |
n4jvp is both the file owner and a member of the powerUsers group
-r--rwx--- 1 n4jvp powerUsers 4096 Jan 27 10:00 script.shpermissions are r--rwx---permissions are match sequentially until a match is found when n4jvp is the owner a match has been found with the owner's permission as the owner n4jvp can only read the file it doesn't matter that n4jvp is also a member of the powerUsers group The 'Root' Exception
the root user (or a user running sudo) can read, write, or execute any file on the system, regardless of the permissions
|
| Changing Permissions: chmod with Symbolic and Numeric Modes |
|
use chmod (Change Mode) command to change permissions two ways to use chmod Symbolic Mode (Human Readable)
construct a command using three parts
to add execute permissions for the owner chmod u+x <object name>to remove write permissions for the group chmod g-w <object name>to add read permissions for everyone chmod a+r <object name>to remove all permissions for others chmod o-rwx <object name> Numeric Mode (Octal System)
faster as it can set all permissions at onceeach premission is assigned a number
add numbers together to create a permission set
Permission Values
|
| Changing Ownership: chown and chgrp |
|
Changing Owner (chown)
syntax
sudo chown <new owner> <object name> Changing Group (chgrp)
syntax
sudo chgrp <new group> <object name> Combining the chown and chgrp
can change both the user and the group at the same time using chown with a colon separatorsyntax sudo chown <user>:<group> <filename>example sudo chown anna:finance budget.xls Recursive Ownership
to change ownership of all files in a folder use the Recursive -R flag
sudo chown -R anna:marketing /opt/marketing_materials |
| Special Permissions: SUID, SGID, and Sticky Bit |
|
beyond the standard rwx, there are three 'Special' permission bits used for specific security scenarios
SUID (Set User ID)
the SUID bit lets the app execute as the owner and not the usertemporarially executes with root privileges
GID (Set Group ID)
used mostly on directories for collaborationnormally when a file is created, it takes the user's default group setting the SGID bit on a directory makes any file created in the directory inherit the directory's group
The Sticky Bit
used for shared temporary directoriesif the user has write permission, anyone can delete any file sticky bit s adds rule so only the owner can delete the file
|
| Understanding umask and Default Permissions |
|
touch sets default permissions as 644 (rw-r--r--) is determined by the umask (User File Creation Mode Mask) numeric block for a file's full permissions is 666 numeric block for a directory's full permissions is 777 umask is a cookie cutter which removes permssions from a nmeric block default umask in most distributions is 022 subtracting umask from full block yields 644 (rw-r--r--) Checking the umask Value
enter 'umask' in the terminalin my Ubuntu install the response was 0002others can only read the files in the directory Changing the umask Value
quote from the text
If you want all your new files to be private by default, you can set your umask to 077 666 - 077 = 600 (Read/Write for User, nothing for anyone else) You can add the line umask 077 to your shell configuration file (.bashrc) to make this permanent |
| Practical Permission Scenarios and Security Best Practices |
|
Real World Scenario: The Web Server
website HTML files are in /var/www/html
Real World Scenario: The Private SSH Key
SSH - Secure SHell protocolkey file is 'id_rsa' SHH doesn't work because key is 'too open' SSH requires private keys accessible only by the owner chmod 600 id_rsa Real World Scenario: The Un-runnable Script
pythos script hello.py generates a Permission Denied errorby default files are not executable explicitly grant execute permission chmod +x hello.pyor chmod 755 hello.py Real World Scenario: The Locked Folder
have Read permission but can't Execute (x) on the folderExecute is the ability to enter resolve with command chmod u+x <folder name> Security Best Practices
|
| Summary |
covered
key points
|