Linux Permission
Linux Permission
2. Permission Types
Permissions define what actions are allowed:
Read (r): View the file's contents or list directory contents.
Write (w): Modify file contents or add/delete files in a directory.
Execute (x): Run a file as a program or enter a directory.
3. Permission Representation
Symbolic Format:
-rwxr-xr--
The first character indicates the file type:
o -: Regular file.
o d: Directory.
o l: Symbolic link.
Example: 755
Owner: Read, Write, Execute.
Group: Read, Execute.
Others: Read, Execute.
Ref: https://chmod-calculator.com/
6. Directory Permissions
Execute (x): Allows entering the directory.
Write (w): Allows creating, deleting, or renaming files inside the directory.
Example:
Grant full access to a directory:
chmod 777 my_directory
(Use cautiously as this gives access to everyone.)
7. Special Permissions
1. Setuid (s):
o A file executed with the privileges of its owner.
o Set using:
o Set using:
o Set using:
chmod +t mydirectory
8. Practical Examples
1. Make a script executable:
chmod +x myscript.sh
2. Restrict access to sensitive files:
chmod o-rwx sensitive_file.txt
3. Allow group write access:
chmod g+w shared_log.txt
Important Notes
Incorrect permissions can expose your system to security risks.
Always double-check and back up critical files before altering permissions.
Consider using Access Control Lists (ACLs) for advanced permission
management.
Assignment -Permisisons
Execute commands and take screenshots and upload as single file
1. Understanding Permissions
Exercise 1.1: Viewing File Permissions
1. Create a test file:
touch testfile.txt
2. Check the file's permissions:
ls -l testfile.txt
o Observe the rw-r--r-- output and identify the owner, group, and
others' permissions.
3. Directory Permissions
Exercise 3.1: Creating and Modifying a Directory
1. Create a directory:
mkdir mydir
2. Set its permissions to 750:
chmod 750 mydir
3. Verify the changes:
ls -ld mydir
4. Test the permissions:
o Try creating a file inside mydir as the owner.
4. Group Permissions
Exercise 5.1: Assigning a Group
1. Create a new group:
sudo groupadd testgroup
2. Add the current user to the group:
sudo usermod -aG testgroup $(whoami)
3. Assign the group to a file:
chown :testgroup testfile.txt
4. Set group permissions to rw-:
chmod 660 testfile.txt