What do the Linux file permissions rwx mean and how does chmod work?
Understand Linux rwx file permissions and how chmod works, with numeric and symbolic modes, directory rules and clear examples for interviews.
Expected Interview Answer
In Linux, rwx are the three permission bits — read (r), write (w) and execute (x) — granted separately to three classes: the file's owner (user), its group, and others; chmod is the command that changes these bits.
Each file stores nine permission bits shown as three rwx groups, one per class. chmod sets them either symbolically (chmod u+x file) or numerically, where r=4, w=2 and x=1 are summed per class (chmod 754 gives owner 7=rwx, group 5=r-x, others 4=r--). For directories, r lists contents, w allows creating or deleting entries, and x permits entering the directory and accessing files inside.
- Controls who can read, modify or run each file
- Enforces basic multi-user security
- Distinguishes owner, group and everyone else
- Numeric mode makes bulk changes fast
- Symbolic mode makes targeted edits clear
AI Mentor Explanation
Think of the team dressing room. The captain (owner) can open his locker, change its contents and walk in freely — that is read, write and execute. Support staff (group) may look and enter but not rearrange kit. Visiting fans (others) get no access at all. chmod is the board deciding, per role, exactly who may look, alter, or step inside each locker.
Step-by-Step Explanation
Step 1
Read the permission string
Run ls -l; the first character is the file type and the next nine are three rwx triplets for owner, group and others.
Step 2
Map letters to numbers
Assign r=4, w=2, x=1 and add them within each class, so rwx=7, rw-=6, r-x=5, r--=4.
Step 3
Choose a mode style
Use numeric mode (chmod 754 file) for a full reset, or symbolic mode (chmod g+w file) to tweak one class.
Step 4
Apply chmod
Run chmod 750 script.sh to set owner rwx, group r-x, others none; add -R to recurse into a directory tree.
Step 5
Verify the result
Re-run ls -l and confirm the triplets match what you intended before relying on the file.
What Interviewer Expects
- Knows the three permission classes: user, group, others
- Explains r, w, x meaning for both files and directories
- Can convert between symbolic and numeric modes
- Understands the 4-2-1 numeric scheme
- Mentions execute is required to enter a directory
Common Mistakes
- Confusing the group and others classes
- Thinking execute on a directory means running it
- Forgetting that write on a directory allows deleting files
- Miscalculating numeric modes (e.g. saying rwx is 8)
- Using chmod 777 as a lazy fix for permission errors
Best Answer (HR Friendly)
“Linux permissions decide who can read, change or run a file, split between the owner, a group and everyone else. The chmod command turns those switches on or off, either by naming them directly or by using a short number code.”
Code Example
# View current permissions
ls -l script.sh
# -rw-r--r-- 1 alice devs 240 Jul 21 10:00 script.sh
# Numeric: owner rwx, group r-x, others r-x
chmod 755 script.sh
# Symbolic: add execute for the owner only
chmod u+x script.sh
# Recurse: give the group write on a whole tree
chmod -R g+w project/Follow-up Questions
- What does chmod 777 do and why is it risky?
- How do read, write and execute differ on a directory?
- What is the difference between chmod and chown?
- What does the setuid or sticky bit do?
- How does umask affect default permissions on new files?
MCQ Practice
1. What numeric mode gives the owner rwx, the group r-x and others r-x?
Owner rwx=7, group r-x=5, others r-x=5, so the mode is 755.
2. On a directory, which permission is required to cd into it and access files inside?
Execute (x) on a directory grants the ability to enter it and reach the files it contains.
3. Which command adds execute permission for only the file's owner?
u+x targets the user (owner) class specifically, unlike +x which affects all classes subject to umask.
Flash Cards
What do r, w and x stand for? — Read, write and execute permissions granted per class.
Numeric values of r, w, x? — r=4, w=2, x=1; sum them within each class.
Three permission classes? — Owner (user), group and others.
What does chmod 640 mean? — Owner rw-, group r--, others no access.
Why does x matter on a directory? — It lets you enter the directory and access files inside.