Linux Permissions & Sudo
1 Global Definitions
- File Permissions: Rules that define who can read, write, or execute a file in Linux.
- Ownership: Each file is owned by a user and a group, which determines access rights.
- Sudo (Superuser Do): A command that allows authorized users to execute commands with root privileges.
1.1 Permission Basics
Permission Types
Linux permissions are represented as three categories: user, group, and others.
r
β readw
β writex
β execute
Viewing Permissions
Use the ls -l
command to view file permissions.
- Example:
-rwxr-xr--
- First character: file type (
-
=file,d
=directory) - Next nine characters = user/group/others permissions
Changing Permissions
Modify permissions using the chmod
command.
chmod 755 script.sh
- Symbolic mode:
chmod u+x file.sh
1.2 File Ownership
Changing Ownership
Use chown
and chgrp
to change file ownership.
chown user file.txt
β change file ownerchgrp group file.txt
β change group ownership
Default Permissions (umask)
Defines the default permission settings for new files and directories.
umask
β shows current maskumask 022
β sets default permissions
1.3 Special Permissions
SetUID
Executes a file with the permissions of the fileβs owner.
- Example:
passwd
command - Represented as
s
in user permissions
SetGID
Executes a file with the permissions of the fileβs group.
- Applied to directories β new files inherit group ownership
- Represented as
s
in group permissions
Sticky Bit
Restricts file deletion in shared directories.
- Only file owner or root can delete files
- Common in
/tmp
directory - Represented as
t
in othersβ execute field
1.4 Using Sudo
Basic Usage
Run commands with elevated privileges.
sudo command
sudo apt update
β update system packages
Sudoers File
Defines which users can run commands as root.
- Located at
/etc/sudoers
- Edit with
visudo
for safety
Security Considerations
Sudo prevents unnecessary use of root account.
- Logs all privileged commands
- Allows fine-grained control (e.g., specific commands)
1.5 Why Permissions & Sudo Matter
Linux permissions form the first line of defense in system security by controlling access to files and resources. Sudo provides a safe way to perform administrative tasks without exposing the root account. Together, they reduce the risk of accidental damage and unauthorized privilege escalation.