Permissions
This guide covers Linux file permissions, ownership, and access control.
π Understanding Permission Structure
Basic Permission Format
-rwxrwxrwx 1 owner group size date filename
βββ¬βββ¬βββ¬β
β β β ββ Other permissions
β β βββββ Group permissions
β ββββββββ Owner permissions
ββββββββββ File typePermission Types
r(4): Read permissionw(2): Write permissionx(1): Execute permission-: No permission
File Types
-: Regular filed: Directoryl: Symbolic linkb: Block devicec: Character devices: Socketp: Named pipe
π§ Changing Permissions
Using chmod with Symbolic Mode
chmod u+x file # Add execute permission for user
chmod g-w file # Remove write permission for group
chmod o=r file # Set read-only permission for others
chmod a+x file # Add execute permission for all
chmod u+x,g+w file # Multiple changesUsing chmod with Octal Mode
chmod 755 file # rwxr-xr-x
chmod 644 file # rw-r--r--
chmod 777 file # rwxrwxrwx (use cautiously!)
chmod 600 file # rw-------
chmod 700 directory # rwx------ (common for directories)π₯ Ownership Management
Changing Owner and Group
chown user file # Change owner
chown user:group file # Change owner and group
chown :group file # Change group only
chgrp group file # Alternative way to change groupRecursive Changes
chmod -R 755 directory # Recursive permission change
chown -R user:group directory # Recursive ownership changeπ Special Permissions
SUID (Set User ID) - 4000
chmod u+s file # Add SUID
chmod 4755 file # Add SUID (octal)Executes with owner's permissions
Appears as 's' in user execute position
SGID (Set Group ID) - 2000
chmod g+s file # Add SGID
chmod 2755 file # Add SGID (octal)Executes with group's permissions
Appears as 's' in group execute position
Sticky Bit - 1000
chmod +t directory # Add sticky bit
chmod 1755 directory # Add sticky bit (octal)Only owner can delete files
Common on /tmp directory
π Access Control Lists (ACL)
Viewing ACLs
getfacl file # View ACLSetting ACLs
setfacl -m u:user:rwx file # Set user ACL
setfacl -m g:group:rx file # Set group ACL
setfacl -x u:user file # Remove user ACL
setfacl -b file # Remove all ACLsπ‘ Best Practices
Security
Use least privilege principle
Regularly audit permissions
Avoid 777 permissions
Be cautious with SUID/SGID
Directory Permissions
755 for public directories
750 for group-shared directories
700 for private directories
File Permissions
644 for regular files
600 for sensitive files
755 for scripts
400 for read-only files
π¨ Common Issues and Solutions
Permission Denied
# Check current permissions
ls -l file
# Check current user/group
id
# Check if user is in required group
groups username
# Add necessary permissions
chmod u+rw fileInheritance
# Set default permissions for new files
umask 022 # Results in 755/644
# Set default ACLs
setfacl -d -m u::rwx,g::rx,o::rx directoryπ Troubleshooting
Cannot Access File
Check file permissions
Check directory permissions
Verify ownership
Check parent directory permissions
Cannot Execute Script
Ensure execute permission is set
Check shebang line
Verify file is on executable path
Group Access Issues
Verify group membership
Check group permissions
Ensure proper group ownership
Last updated
Was this helpful?