Master Linux Permissions: User Switching, sudo, chmod, umask & Sticky Bit Explained
This comprehensive guide explains Linux permissions, covering the roles of root and regular users, how to switch users with su, elevate privileges with sudo, manage file and directory access using chmod, chown, chgrp, understand default permission masks with umask, and secure shared directories with the sticky bit, complete with practical command examples and explanations.
Introduction
Linux is an open‑source Unix‑like operating system known for its flexibility, stability, and high performance, widely used in servers, embedded systems, supercomputers, and desktops.
Linux Kernel Overview
Hardware abstraction : abstracts CPU, memory, disks, etc., into usable interfaces.
Resource management : allocates CPU time, memory, file systems, and other resources.
System call interface : provides APIs for user programs to request kernel services.
Device drivers : manage hardware devices such as keyboards, displays, and network cards.
Shell as Command Interpreter
The shell is the user interface to the kernel, interpreting commands and translating them into system calls that control the operating system.
User Permissions
Linux defines two main user types:
root user : the super‑administrator with unrestricted access to all system resources.
regular user : limited permissions for everyday tasks.
The root prompt is # and the regular user prompt is $.
Switching Users
From a regular user to root: su Enter the root password when prompted.
From root back to a regular user: exit Switch to a specific user: su username Login with a fresh environment (similar to re‑login):
su -Using sudo
The sudo (Superuser DO) command allows a regular user to execute commands with root privileges without logging in as root, reducing the risk of accidental system damage. To use sudo, the user must be listed in /etc/sudoers (edit with vim /etc/sudoers).
Example: sudo apt update Enter the current user’s password, not the root password.
File and Directory Permissions
Each file or directory has three categories of access:
Owner (User) : the file’s creator.
Group : a set of users sharing permissions.
Others : everyone else.
Permission Representation
Permissions are expressed with the symbols r (read), w (write), and x (execute). A typical permission string has ten characters, e.g., -rwxr-xr--, where the first character indicates the file type ( - for regular file, d for directory, l for symbolic link, etc.). The remaining nine characters are grouped in threes for owner, group, and others.
Numeric (octal) representation assigns values: r=4, w=2, x=1. For example, 754 corresponds to rwxr-xr--.
Changing Permissions with chmod
Symbolic mode examples:
chmod u+x file.txt # add execute for owner chmod g-w file.txt # remove write for group chmod o+r file.txt # add read for others chmod o=r filename # set others to read‑onlyNumeric mode examples:
chmod 754 file.txt # rwxr-xr-- chmod -R 755 /path/to/dir # recursive changeChanging Owner and Group
Use chown and chgrp:
chown user file.txt chgrp group file.txt chown user:group file.txt chown -R user:group /path/to/dirumask – Default Permission Mask
The umask command defines which permission bits are masked off for newly created files and directories. Default permissions are 666 for files and 777 for directories; the umask subtracts bits to produce the final mode.
umask is a three‑digit octal value (the leading zero is for special bits and can be ignored). Each digit masks read (4), write (2), and execute (1) for owner, group, and others respectively.
Common examples: umask 0002 masks write permission for others. umask 0033 masks write and execute for group and others.
View current umask: umask Set a new umask:
umask 022Directory Permissions
Read ( r) allows listing contents, write ( w) permits creating, deleting, or renaming entries, and execute ( x) allows entering the directory. Write permission alone is ineffective without execute.
Sticky Bit
The sticky bit ( t) on a directory ensures that only the file’s owner, the directory’s owner, or root can delete or rename files within that directory, even if others have write permission. It is commonly set on shared directories such as /tmp: drwxrwxrwt # trailing 't' indicates sticky bit Set sticky bit: chmod +t directory or using octal: chmod 1775 directory # 1000 adds sticky bit Remove sticky bit: <code>chmod -t directory</code> or: <code>chmod 0775 directory</code>
Conclusion
Understanding Linux permissions, user switching, sudo usage, and tools like chmod , chown , umask , and the sticky bit is essential for secure and efficient system administration.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
