Permissions — File ownership and access control
chmod
Permissions
Change file permissions
Syntax
chmod [OPTIONS] MODE FILE...
Examples
chmod 755 script.sh chmod +x script.sh chmod -R 644 /var/www/html chmod u+w file.txt
Common Flags
-R apply recursively
Notes
Octal: 7=rwx 6=rw- 5=r-x 4=r-- 0=---. Common: 755 for dirs/executables, 644 for files.
chown
Permissions
Change file owner and group
Syntax
chown [OPTIONS] OWNER[:GROUP] FILE...
Examples
chown alice file.txt chown alice:www-data /var/www/html chown -R alice:www-data /home/alice/myapp
Common Flags
-R apply recursively
id
Permissions
Print user and group information
Syntax
id [USER]
Examples
id id alice
su
Permissions
Switch user
Syntax
su [OPTIONS] [USER]
Examples
su - su - alice
Common Flags
- start a login shell (loads the user's environment)
sudo
Permissions
Execute a command as another user (default: root)
Syntax
sudo [OPTIONS] COMMAND
Examples
sudo apt update sudo systemctl restart nginx sudo -u postgres psql
Common Flags
-u USER run as specified user
-i open an interactive root shell
-l list allowed commands
umask
Permissions
Set default permissions for new files
Syntax
umask [MASK]
Examples
umask umask 022
Notes
umask 022 means new files get 644, new dirs get 755.