Master Linux Permissions: Complete Guide for Beginners
This comprehensive tutorial explains Linux permission concepts, user classifications, file type symbols, basic read/write/execute rights, numeric and symbolic representations, essential commands like chmod, chown, chgrp, and umask, as well as special permissions such as the sticky bit, providing clear examples and usage tips for effective system administration.
Understanding Linux Permissions: A Comprehensive Guide for Beginners
1. Linux Permission Concepts
In Linux, permissions control user access to files and directories. Each file and directory has three basic permissions: read (r), write (w), and execute (x). These permissions apply to three classes of users: the file owner (
u), the owning group (
g), and others (
o).
1.1 User Classification
Linux has two types of users:
Superuser (root) : can perform any action without restriction.
Regular user : limited to permitted operations.
Superuser prompt is
#, regular user prompt is
$.
1.2 Syntax
su [username]1.3 Function
Switch user.
2. Linux Permission Management
2.1 File Accessor Categories
User (u) : the owner of the file or directory.
Group (g) : the group that owns the file or directory.
Others (o) : all users other than the owner and group.
2.2 Permission Representation
2.3 File Types
d: directory
-: regular file
l: symbolic link
b: block device
p: pipe
c: character device
s: socket
2.4 Basic Permissions
Read (r) : view file contents or list directory contents.
Write (w) : modify file contents or create/delete files in a directory.
Execute (x) : run a file or enter a directory.
- : indicates the permission is not granted.
2.5 Permission Value Representations
a) Symbolic notation
b) Octal notation
2.6 Permission Management Commands
The main commands for managing permissions are:
1. chmod command
Change file or directory permissions.
chmod [options] mode fileExamples:
chmod u+rwx file.txt # give owner read, write, execute
chmod g-w file.txt # remove write from group
chmod o=rx file.txt # set others to read and execute only
chmod 755 file.txt # set permissions to rwxr-xr-x
chmod -R 755 directory # recursively change permissions2. chown command
Change file or directory owner.
chown [options] owner[:group] fileExamples:
chown user file.txt # change owner to user
chown user:group file.txt # change owner to user and group to group
chown -R user:group directory # recursively change owner and group3. chgrp command
Change file or directory group.
chgrp [options] group fileExamples:
chgrp group file.txt # change group to group
chgrp -R group directory # recursively change group4. umask command
Set the default permission mask for newly created files and directories.
umask [options] [mask]Examples:
umask 022 # default permissions become 755 for directories, 644 for files
umask 077 # new files/directories are accessible only by the owner (600/700)In Linux, the umask determines the default permissions by masking bits from the base permissions (666 for files, 777 for directories).
a) How umask works
Default file permission 666 minus umask 022 equals 644 (rw-r--r--). Default directory permission 777 minus umask 022 equals 755 (rwxr-xr-x).
b) Viewing and setting umask
View current umask:
umaskSet umask:
umask 022c) Permanent umask configuration
Add a line like
umask 022to the user's shell profile (e.g.,
.bashrcor
.profile).
d) Special Cases
umask 000: new files get maximum permissions (666/777) – not recommended for security.
umask 077: new files/directories are accessible only by the owner (600/700) – suitable for high‑security scenarios.
2.7 Special Permissions (Sticky Bit)
The sticky bit restricts deletion or renaming of files in a directory to the file owner or root, even if other users have write permission.
1. Purpose of the Sticky Bit
Commonly used on public directories such as
/tmpto prevent users from deleting each other's files. When set, the other‑users execute bit appears as
t(or
Tif execute is not set).
2. Setting the Sticky Bit
Use
chmod:
chmod +t directory # set sticky bit
chmod -t directory # remove sticky bit3. Example
Check
/tmppermissions:
ls -ld /tmp
# drwxrwxrwt 10 root root 4096 ... /tmpCreate a directory with sticky bit:
mkdir mydir
chmod 1777 mydir # rwxrwxrwt
ls -ld mydir4. Notes
The sticky bit only applies to directories, not files.
After setting it, other users can modify file contents but cannot delete or move the files.
Proper use of the sticky bit helps protect files in shared directories from unauthorized deletion or movement.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.