Linux File Permissions: chmod, chown, chgrp, umask, SUID, SGID and Sticky Bit Explained
Every file and folder in Linux has an owner, a group and three sets of rights: read, write and execute for the owner, the group and everyone else. In this chapter you learn to read ls -l, change rights with chmod (numbers and letters), change owners with chown and chgrp, set defaults with umask, and use the special bits SUID, SGID and sticky.
In this chapter
- Read permissions in ls -l and stat
- Know what r, w, x mean for files and for folders
- Use chmod with numbers (755) and letters (u+x)
- Change ownership with chown and chgrp
- Control default rights with umask
- Use SUID, SGID and the sticky bit safely
1. An everyday example: a family photo album
Aai keeps the family album. She can look at it, add photos and remove them. The family (Baba, kids) can look at it and add photos, but not remove them. Guests can only look. The album on the living room table is shared, but each person may take out only the photos they put in.
Aai = owner (user). Family = group. Guests = others. Look = read (r). Add or remove = write (w). Opening the album = execute (x) on a folder. Shared table rule = sticky bit, like /tmp.
2. ls -l: read the permission string
Read -rw-r----- in groups. The first dash means a regular file. rw- gives the owner read and write, r-- gives members of the file’s group read, and --- gives everyone else no access through these mode bits. Compare the file’s owner and group in the ls -l row with your identity from id. For a regular file using only these bits, Linux picks your class and checks the requested right. A person in the group can open the file to read but can’t save changes through that access.
Every 'Permission denied' starts by reading these 10 characters.
-rwxr-x--- means: type (- file, d folder, l link), then owner rwx, group r-x, others ---. Then the link count, owner, group, size, date and name. ls -ld FOLDER shows the folder itself, not its contents. ls -n shows numbers instead of names.
| Position | Example | Meaning |
|---|---|---|
| 1 | d | Type: folder |
| 2-4 | rwx | Owner can read, write, execute |
| 5-7 | r-x | Group can read and execute |
| 8-10 | --- | Others have nothing |
- A script.
ls -l deploy.sh
Output:
-rwxr-x--- 1 ravi devs 812 Oct 25 10:10 deploy.sh
ravi full, devs read and run, others nothing.
- A folder itself.
ls -ld /srv/shared
Output:
drwxrwsr-x 2 root devs 4096 Oct 25 10:12 /srv/shared
s in group x place = SGID (covered below).
- Numbers, not names.
ls -ln deploy.sh
Output:
-rwxr-x--- 1 1001 3001 812 Oct 25 10:10 deploy.sh
Useful when a user was deleted.
3. r, w, x on files vs folders
People give r on a folder and wonder why cd fails. The meaning changes for folders.
File: r read content, w change content, x run it as a program. Folder: r list names (ls), w create, delete or rename entries inside, x enter it and reach files inside (cd, open by path). To delete a file you need w on the FOLDER, not on the file.
| Bit | On a file | On a folder |
|---|---|---|
| r | Read content | List names |
| w | Change content | Add, delete, rename inside |
| x | Run it | Enter and pass through |
- Folder with r but no x.
chmod 744 box && sudo -u priya ls box; sudo -u priya cat box/a.txt
Output:
ls: cannot access 'box/a.txt': Permission denied
a.txt
cat: box/a.txt: Permission denied
She sees names but cannot open them.
- Folder with x but no r.
chmod 711 box && sudo -u priya ls box; sudo -u priya cat box/a.txt
Output:
ls: cannot open directory 'box': Permission denied
hello
She cannot list, but can open a known name.
- Deleting needs w on the folder.
ls -ld /etc && rm /etc/passwd-test
Output:
dr-xr-xr-x. ... root root /etc
rm: cannot remove '/etc/passwd-test': Permission denied
The file's own bits do not matter here.
4. chmod with numbers (octal)
Try reading 640 without memorising it. The owner digit is 6, which is 4 for read plus 2 for write. The group digit is 4, so its members can read. Other users get the last digit, zero. To let the owner execute the same file as well, change only the owner digit to 7. Predict that ls -l will start with -rwxr----- after chmod 740 on your own test file, then compare what you see.
Numbers set all three groups at once and are what docs and tickets use: 644, 755, 600.
r=4, w=2, x=1. Add them per set: 7=rwx, 6=rw-, 5=r-x, 4=r--, 0=---. Three digits are owner, group, others. A fourth digit in front sets special bits (4 SUID, 2 SGID, 1 sticky). -R changes a whole tree (careful).
| Number | Letters | Typical use |
|---|---|---|
| 644 | rw-r--r-- | Normal files, web pages |
| 600 | rw------- | Private keys, secrets |
| 755 | rwxr-xr-x | Scripts, folders |
| 700 | rwx------ | Private folders, ~/.ssh |
| 640 | rw-r----- | Config read by a group |
| 775 | rwxrwxr-x | Team folder |
- Make a key private.
chmod 600 ~/.ssh/id_ed25519 && ls -l ~/.ssh/id_ed25519
Output:
-rw------- 1 ravi ravi 411 Oct 25 id_ed25519
SSH refuses keys that others can read.
- A script everyone can run.
chmod 755 backup.sh && ls -l backup.sh
Output:
-rwxr-xr-x 1 ravi ravi 540 Oct 25 backup.sh
7 owner, 5 group, 5 others.
- Config readable by the app group.
sudo chmod 640 /etc/billing/db.conf && ls -l /etc/billing/db.conf
Output:
-rw-r----- 1 root billing 210 Oct 25 db.conf
Others cannot see the DB password.
- Never do this.
chmod -R 777 /var/www
Output:
(no output)
Anyone can change your site. Use 755 folders and 644 files.
5. chmod with letters (symbolic)
Often you want to add or remove one right without touching the rest, like making a script runnable.
Who: u owner, g group, o others, a all. Action: + add, - remove, = set exactly. What: r w x, X (x only on folders or files already executable), s, t. You can combine: chmod u=rwx,g=rx,o= file.
- Make a script runnable.
chmod u+x run.sh && ls -l run.sh
Output:
-rwxr--r-- 1 ravi ravi 120 Oct 25 run.sh
Only the owner gets x.
- Remove rights for others.
chmod o-rwx salary.xlsx && ls -l salary.xlsx
Output:
-rw-r----- 1 hr hr 88K Oct 25 salary.xlsx
Others lose everything.
- Set exactly.
chmod u=rw,g=r,o= report.pdf && stat -c '%A %a' report.pdf
Output:
-rw-r----- 640
= replaces old bits for that set.
- Fix a web tree in one command.
chmod -R u=rwX,g=rX,o=rX /var/www/site
Output:
(no output)
Capital X gives x to folders only, so files stay 644 and folders 755.
chmod in depth: numeric vs symbolic side by side
You will meet both forms in docs and scripts. You must be able to read one and write the other.
Numeric sets all bits at once (r=4, w=2, x=1). Symbolic changes only what you name (u g o a, + - =). Both can use -R for a folder tree.
Common options
| Option | What it does |
|---|---|
644 = u=rw,g=r,o=r | Normal file. |
755 = u=rwx,g=rx,o=rx | Script or folder others can enter. |
600 = u=rw,go= | Secret file. |
700 = u=rwx,go= | Private folder. |
g+w | Add write for group only; keep the rest. |
-R | Apply to everything inside a folder. |
- Check the start.
ls -l plan.txt
Output:
-rw-r--r-- 1 arjun team 900 Oct 25 plan.txt
Now it is 644.
- Add group write with symbolic.
chmod g+w plan.txt && stat -c %a plan.txt
Output:
664
Only the group part changed.
- Set exact rights with numbers.
chmod 640 plan.txt && ls -l plan.txt
Output:
-rw-r----- 1 arjun team 900 Oct 25 plan.txt
Owner rw, group r, others nothing.
- Same result in symbolic form.
chmod u=rw,g=r,o= plan.txt && stat -c %a plan.txt
Output:
640
Two ways, one result.
Practise this in the tasks below: Practice tasks
6. stat: exact permissions and times
ls hides the number and some details. stat shows the octal mode, owner IDs and all three times.
stat FILE prints size, inode, mode, UID/GID and access/modify/change times. stat -c '%a %U %G %n' prints a custom line: %a octal, %A letters, %U owner, %G group.
- Full details.
stat /etc/passwd | sed -n '1p;4p'
Output:
File: /etc/passwd
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
0644 in numbers.
- Short form for many files.
stat -c '%a %U:%G %n' /etc/shadow /etc/sudoers
Output:
0 root:root /etc/shadow
440 root:root /etc/sudoers
Great for audits.
7. chown: change owner and group
Files copied as root, uploads by the web server, or restored backups end up with the wrong owner and the app cannot write.
sudo chown USER FILE changes owner. chown USER:GROUP FILE changes both. chown :GROUP FILE only group. -R for a tree. --reference=OTHER copies owner from another file. Only root can give files away.
- Give the app folder to the app user.
sudo chown -R deploy:deploy /srv/app && ls -ld /srv/app
Output:
drwxr-xr-x 5 deploy deploy 4096 Oct 25 /srv/app
Everything inside now belongs to deploy.
- Owner and group for uploads.
sudo chown nginx:www /srv/app/uploads
Output:
(no output)
The web server can write uploads.
- Normal user cannot give away.
chown priya notes.txt
Output:
chown: changing ownership of 'notes.txt': Operation not permitted
Only root can change the owner.
- Copy ownership from another file.
sudo chown --reference=/etc/nginx/nginx.conf /etc/nginx/conf.d/shop.conf
Output:
(no output)
Same owner and group as nginx.conf.
chown in depth: user:group and -R
Web servers, apps and teams need the right owner. A wrong owner gives "Permission denied" even with good chmod bits.
chown USER file sets the owner. USER:GROUP sets both. :GROUP sets only the group. -R does the whole tree. Changing owner needs sudo.
Common options
| Option | What it does |
|---|---|
chown user f | Owner only. |
chown user:group f | Owner and group. |
chown :group f | Group only (like chgrp). |
chown user: f | Owner, and group = that user's main group. |
-R | Whole folder tree. |
-v / -c | Print every change / only real changes. |
- See who owns it.
ls -l /srv/blog/index.html
Output:
-rw-r--r-- 1 root root 2.1K Oct 25 /srv/blog/index.html
root owns it, so the app user cannot edit.
- Set owner and group together.
sudo chown -v www-data:www-data /srv/blog/index.html
Output:
changed ownership of '/srv/blog/index.html' from root:root to www-data:www-data
Both parts changed in one command.
- Only the group.
sudo chown :editors /srv/blog/drafts && ls -ld /srv/blog/drafts
Output:
drwxrwxr-x 2 www-data editors 4096 Oct 25 /srv/blog/drafts
Owner stayed, group is editors.
- Whole tree with -R, show only real changes.
sudo chown -Rc www-data:www-data /srv/blog
Output:
changed ownership of '/srv/blog/drafts' from www-data:editors to www-data:www-data
-c printed only the item that really changed.
Practise this in the tasks below: Practice tasks
8. chgrp: change only the group
A team folder must belong to the team group so all members get group rights.
chgrp GROUP FILE changes the group. A normal user can do it if they own the file and are a member of the new group. -R for a tree.
- Hand a report to finance.
chgrp finance q3.xlsx && ls -l q3.xlsx
Output:
-rw-r----- 1 ravi finance 40K Oct 25 q3.xlsx
Finance members can now read it.
- Not a member.
chgrp hr q3.xlsx
Output:
chgrp: changing group of 'q3.xlsx': Operation not permitted
You must be in hr, or use sudo.
9. umask: default rights for new files
Work from what the creating program requests. A regular file often starts with a request for 666, and a directory often starts with 777 because entering a directory needs execute permission. With umask 027 and no default ACL, take away write from the group and all rights from others. The usual result is 640 for the file and 750 for the folder. Create one of each inside a test subshell and compare them with ls -ld. An existing file keeps its mode when you change the umask.
Files created by an app or a user get rights from umask. A wrong umask makes secrets world-readable, or team files unreadable.
New files start from 666, folders from 777, and the umask bits are removed. umask 022 gives 644 files and 755 folders. umask 027 gives 640 and 750. umask 077 gives 600 and 700. umask -S shows letters. Set it in ~/.bashrc, /etc/login.defs or a systemd unit (UMask=).
| umask | New file | New folder |
|---|---|---|
| 022 | 644 | 755 |
| 002 | 664 | 775 |
| 027 | 640 | 750 |
| 077 | 600 | 700 |
- Check your umask.
umask; umask -S
Output:
0022
u=rwx,g=rx,o=rx
The usual default.
- See it in action.
umask 077; touch secret.txt; mkdir private; ls -ld secret.txt private
Output:
-rw------- 1 ravi ravi 0 secret.txt
drwx------ 2 ravi ravi 4096 private
Only you can touch them.
- Team-friendly umask.
umask 002; touch shared.txt; ls -l shared.txt
Output:
-rw-rw-r-- 1 ravi devs 0 shared.txt
Group can write too.
- Set it for a service.
sudo systemctl edit billing # add: [Service] UMask=0027
Output:
(editor opens)
Files the service writes get 640.
10. SUID (4000): run as the file owner
passwd must write /etc/shadow, which only root can. SUID lets a normal user run it with root's power, only for that program.
SUID on an executable makes it run with the owner's UID. It shows as s in the owner x place (S if x is missing). Set with chmod u+s or chmod 4755. It is ignored on scripts and on file systems mounted nosuid. Every extra SUID binary is an attack target: audit them.
- The classic example.
ls -l /usr/bin/passwd
Output:
-rwsr-xr-x. 1 root root 32648 /usr/bin/passwd
s: it runs as root for every user.
- Find all SUID files.
sudo find / -xdev -perm -4000 -type f 2>/dev/null | head -4
Output:
/usr/bin/passwd
/usr/bin/sudo
/usr/bin/su
/usr/bin/mount
Compare with a known-good list.
- Remove SUID from a risky copy.
sudo chmod u-s /opt/tools/oldping && ls -l /opt/tools/oldping
Output:
-rwxr-xr-x 1 root root 7k oldping
No longer runs as root.
11. SGID (2000): group inheritance
In a team folder, files made by each person get their own group, and teammates cannot edit them. SGID on the folder fixes this.
On a folder, SGID makes new files and folders inside take the folder's group (new sub-folders get SGID too). On a program, it runs with the file's group. Shows as s in the group x place. Set with chmod g+s or chmod 2775.
- Create a team folder.
sudo mkdir /srv/devs && sudo chgrp devs /srv/devs && sudo chmod 2775 /srv/devs && ls -ld /srv/devs
Output:
drwxrwsr-x 2 root devs 4096 Oct 25 /srv/devs
s in the group part.
- New files get the team group.
touch /srv/devs/plan.md && ls -l /srv/devs/plan.md
Output:
-rw-rw-r-- 1 ravi devs 0 Oct 25 plan.md
Group is devs, not ravi.
- Pair with umask 002.
umask 002; echo hi > /srv/devs/notes.txt; ls -l /srv/devs/notes.txt
Output:
-rw-rw-r-- 1 ravi devs 3 notes.txt
Teammates can edit.
12. Sticky bit (1000): only owners delete
In a folder everyone can write, like /tmp, anyone could delete anyone's files. The sticky bit stops that.
On a folder, sticky means only the file owner, the folder owner or root can delete or rename a file. Shows as t in the others x place. Set with chmod +t or chmod 1777.
- See it on /tmp.
ls -ld /tmp
Output:
drwxrwxrwt. 18 root root 4096 Oct 25 /tmp
t at the end.
- A shared upload folder.
sudo mkdir /srv/drop && sudo chmod 1777 /srv/drop
Output:
(no output)
Everyone can add, only owners can remove.
- Try deleting someone else's file.
sudo -u priya rm /srv/drop/ravi.txt
Output:
rm: cannot remove '/srv/drop/ravi.txt': Operation not permitted
The sticky bit protected it.
13. Putting it together: safe permission recipes
Most real tasks are the same few patterns. Learn them once.
Web root: owner deploy, group nginx, folders 2750, files 640. SSH: ~/.ssh 700, keys 600, authorized_keys 600. Secrets: 600 or 640 with an app group. Team share: SGID 2775 plus umask 002. Shared drop: 1777.
- Fix SSH folder rights.
chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys && stat -c '%a %n' ~/.ssh ~/.ssh/authorized_keys
Output:
700 /home/ravi/.ssh
600 /home/ravi/.ssh/authorized_keys
sshd ignores keys if these are too open.
- Web root recipe.
sudo chown -R deploy:nginx /srv/www && sudo find /srv/www -type d -exec chmod 2750 {} + && sudo find /srv/www -type f -exec chmod 640 {} +
Output:
(no output)
nginx can read, only deploy can write.
- Find world-writable files to fix.
sudo find /srv -xdev -type f -perm -o+w
Output:
/srv/www/config.php
Fix with chmod o-w.
14. Real examples from many industries
The same Linux skill shows up in every kind of company. Seeing it in many places helps you remember it.
Each row is a made-up team. It shows who uses this and how.
| Team and city | How they use it | Command |
|---|---|---|
| Kiran, web agency, Nashik | Resets a WordPress tree to 755/644 | find wp -type d -exec chmod 755 {} + |
| Ahmed, bank, Riyadh | Keeps DB configs readable only by the app group | chmod 640 /etc/app/db.conf |
| Sofia, design studio, Lisbon | Team share where everyone can edit | chmod 2775 /srv/design |
| Tom, university, Boston | Shared drop folder for students | chmod 1777 /srv/drop |
| Neha, security audit, Gurugram | Lists SUID binaries every week | find / -xdev -perm -4000 -type f |
| Chen, SaaS, Shenzhen | Sets UMask=0027 for services | UMask=0027 in the systemd unit |
15. Common errors and how to fix them
Everyone hits these errors. Knowing the cause saves hours.
Read the exact message first. Then match it to a row below.
| Error you see | Why it happens | How to fix |
|---|---|---|
bash: ./deploy.sh: Permission denied | No x bit on the script | Add execute.chmod u+x deploy.sh |
cat: /etc/shadow: Permission denied | Normal user lacks r | Use sudo if you really need it.sudo cat /etc/shadow |
chown: changing ownership of 'x': Operation not permitted | Only root can change owners | Use sudo.sudo chown deploy x |
WARNING: UNPROTECTED PRIVATE KEY FILE! Permissions 0644 for 'key.pem' are too open. | SSH key readable by others | chmod 600 the key.chmod 600 key.pem |
Authentication refused: bad ownership or modes for directory /home/ravi | Home or ~/.ssh is group/other writable | Remove g/o write.chmod go-w ~ && chmod 700 ~/.ssh |
rm: cannot remove 'x': Operation not permitted (in /tmp) | Sticky bit: not your file | Ask the owner or use sudo.ls -l /tmp/x |
cd: /srv/data: Permission denied | No x on the folder (or a parent) | Check each folder with namei -l.namei -l /srv/data/file |
nginx: 403 Forbidden | nginx user cannot read files or pass a parent folder | Give r on files and x on every parent.namei -l /srv/www/index.html |
chmod: changing permissions of 'x': Read-only file system | Disk mounted read-only | Check mount and dmesg.mount | grep ' / ' |
Team member cannot edit a shared file | File has the creator's group or umask 022 | Use SGID folder and umask 002.chmod 2775 /srv/devs |
16. Troubleshooting step by step
For 'Permission denied', walk the path from / to the file and check the user, the group and each bit.
Go top to bottom. Stop at the first step that shows the problem.
- Who is the process running as?
ps -o user,group,comm -C nginx
- Check every folder on the path.
namei -l /srv/www/site/index.html
- Exact mode and owner of the file.
stat -c '%A %a %U:%G' /srv/www/site/index.html
- Is it a group problem?
id nginx
- Test as that user.
sudo -u nginx cat /srv/www/site/index.html
- Still denied? Check ACLs and SELinux.
getfacl /srv/www/site/index.html; ls -Z /srv/www/site/index.html
17. Lab 1: Build a team share
Create a folder where every devs member can create and edit files, but others cannot see it.
A full hands-on lab. Run every step on a test Linux machine (an EC2 instance, a VM, or WSL).
- Create users and group.
sudo groupadd -f devs && sudo useradd -m -G devs dev1 && sudo useradd -m -G devs dev2
Output:
(no output)
- Create the folder with SGID.
sudo mkdir -p /srv/team && sudo chgrp devs /srv/team && sudo chmod 2770 /srv/team && ls -ld /srv/team
Output:
drwxrws--- 2 root devs 4096 Oct 25 /srv/team
- dev1 creates a file.
sudo -u dev1 bash -c 'umask 002; echo v1 > /srv/team/plan.txt' && ls -l /srv/team
Output:
-rw-rw-r-- 1 dev1 devs 3 plan.txt
- dev2 edits it.
sudo -u dev2 bash -c 'echo v2 >> /srv/team/plan.txt' && cat /srv/team/plan.txt
Output:
v1
v2
- An outsider is blocked.
sudo -u nobody ls /srv/team
Output:
ls: cannot open directory '/srv/team': Permission denied
18. Lab 2: Numbers, letters, umask and special bits
Practise chmod both ways, see umask results, and find SUID and sticky bits.
A full hands-on lab. Run every step on a test Linux machine (an EC2 instance, a VM, or WSL).
- Numbers.
mkdir -p ~/lab15 && cd ~/lab15 && touch a && chmod 640 a && stat -c '%A %a' a
Output:
-rw-r----- 640
- Letters.
chmod u+x,g-r a && stat -c '%A %a' a
Output:
-rwx------ 700
- umask 027.
(umask 027; touch b; mkdir c) && stat -c '%a %n' b c
Output:
640 b
750 c
- Sticky folder.
mkdir d && chmod 1777 d && ls -ld d
Output:
drwxrwxrwt 2 ravi ravi 4096 d
- SUID count.
sudo find /usr/bin -perm -4000 | wc -l
Output:
14
Ravindra Bagale's Tip
Never fix 'Permission denied' with chmod 777. Find WHO is denied (ps, id), WHERE (namei -l), and give only the missing bit to the right owner or group.
Ravindra Bagale's Tip – मराठी
'Permission denied' कधीच chmod 777 ने fix करू नका. कोणाला denied (ps, id), कुठे (namei -l) ते शोधा, आणि योग्य owner किंवा group ला फक्त missing bit द्या.
Ravindra Bagale's Tip – हिंदी
'Permission denied' को कभी chmod 777 से ठीक न करें. किसे denied है (ps, id), कहाँ (namei -l) पता करें, और सही owner या group को सिर्फ गायब bit दें.
19. Frequently asked questions
Q. What does 755 mean?
Owner rwx (7), group r-x (5), others r-x (5).
Q. Why does my script say Permission denied?
It needs x: chmod u+x script.sh, or run it with bash script.sh.
Q. Can root ignore permissions?
Mostly yes for read and write, but root still needs at least one x bit to run a file, and immutable files or SELinux can still block root.
Q. What is the difference between s and S?
s means the special bit and x are both set. S means the special bit is set but x is missing (usually a mistake).
Q. Does SUID work on shell scripts?
No, Linux ignores SUID on scripts for safety. Use sudo rules instead.
Q. How do I see permissions as numbers?
stat -c '%a %n' FILE.
Q. Why can I delete a file I cannot read?
Delete depends on w and x of the folder, not the file.
Q. Where do I set umask for everyone?
/etc/login.defs (UMASK), /etc/profile or a file in /etc/profile.d; for services use UMask= in the unit.
20. Interview questions and answers
Beginner level
Q. What do r, w and x mean?
Read, write and execute.
Q. What is chmod 644?
Owner read and write; group and others read only.
Q. How do you make a script executable?
chmod +x script.sh.
Q. How do you change a file's owner?
sudo chown user:group file.
Mid level level
Q. What does x mean on a folder?
Permission to enter it and reach files inside.
Q. With umask 027, what are new file and folder rights?
Files 640, folders 750.
Q. What is SGID on a folder used for?
New files inherit the folder's group, for team shares.
Q. Why is /tmp 1777?
Everyone can write, but the sticky bit lets only owners delete their files.
Senior level
Q. nginx returns 403 for a file with 644. Why?
A parent folder lacks x for nginx, the file is outside the allowed root, an ACL denies it, or SELinux context is wrong. Check namei -l, getfacl and ls -Z.
Q. Why is an unexpected SUID root binary dangerous?
Any user who runs it gets root rights in that program; bugs or shell escapes give full root.
Q. How do you prevent SUID abuse on data disks?
Mount them with nosuid,nodev (and noexec where possible), and audit find -perm -4000 regularly.
Q. A deploy breaks because files are owned by root after a CI copy. How do you fix it for good?
Run the copy as the deploy user, or chown in the pipeline, set UMask in the service, and use SGID group folders.
Try at home
- Create a folder 'family' that only you and a group 'home' can open, where new files keep the 'home' group. Prove it with ls -ld and a test file.
- Write down the umask that gives new files 600, and test it.
Practise this chapter
Interview questions and answers
A teammate can open a file but cannot remove it. Which permissions explain this?
Reading the file checks its own mode or ACL. Removing its name is a change to the containing directory, so check write and execute permission there. If the sticky bit is set, also check who owns the file and directory before expecting a removal.
Check your understanding
Choose an answer, then compare your reasoning with the explanation.
Practice Tasks
Practice checks run in your browser. They check the answer for this exercise; they do not create resources or connect to your AWS account.
About this scenarioLondon Legal LLP is a law business in London. Oliver Hughes looks after its IT and cloud work. They count money in GBP and run their AWS resources in the eu-west-2 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.
0 / 21
Easy See permissions
Start every access check here.
Show the permissions of release.sh in long format.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Folder itself
ls -l shows contents otherwise.
Show the permissions of the /srv/projects folder itself, not its contents.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Make a script runnable
Permission denied on ./start.sh.
Add execute for the owner on start.sh, using letters.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Private key
SSH rejects open keys.
Make prod.pem readable and writable only by the owner, using numbers.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Script for everyone
Shared tools at BIZ.
Give sync.sh rwxr-xr-x using numbers.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Change group only
Finance needs the report.
Change the group of payroll.xlsx to hr.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Set umask symbolically
New files get odd rights.
Set the umask in symbolic form so the owner gets rwx, the group rx and others nothing.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Change only the group
Finance team must share it.
Change only the group of budget.xlsx to finance using chown.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Owner and group
App user must own its log.
Make user ravi and group devs the owner and group of app.log.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Add group write
Team edits one file.
Give the group write permission on shared.txt without changing anything else.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Private folder
Keys and backups stay private.
Make the folder private so only the owner can read, write and enter it, using numbers.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Medium Group-readable config
App group reads the DB config.
Set db.conf to rw for owner, r for group, nothing for others, with numbers.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Medium Remove all rights for others
Salary data.
Remove read, write and execute for others on bonus.xlsx.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Medium Mode as a number
Tickets use numbers.
Print only the octal mode of /etc/passwd with stat.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Medium Give the app folder to www
Root-owned files break wwws.
Recursively set owner and group of /srv/web to www.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Medium Private by default
Secrets in this shell.
Set the umask so new files become 660 and folders 770.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Medium Team folder group inheritance
Teammates must edit each other's files.
Set /srv/qa to 2775.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Medium Shared drop folder
Users must not delete each other's files.
Give /srv/uploads the mode 1777.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Hard Fix a web tree
Folders need x, files do not.
Recursively give /var/www/blog u=rwX,g=rX,o=rX.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Hard Audit SGID files
Each SGID root file is a target.
Find regular files with the SGID bit under / on this file system only.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Hard Check every folder on a path
nginx 403 on a 644 file.
Show owner and mode of every part of /var/www/blog/app.js.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
21. Related chapters
- Linux Ops Refresh for DevOps
- Bash Scripting for Automation
- Linux grep and find Commands with Examples
- How to Set Up Passwordless SSH Between Linux Servers
In short
- ls -l: type, owner, group, others; stat for numbers.
- Folder x = enter; delete needs folder w.
- chmod 644/755/600 or u+x, g-w, o=.
- chown user:group, chgrp group, -R with care.
- umask 022 → 644/755; 027 → 640/750.
- SUID 4, SGID 2, sticky 1; never chmod 777.
Revision, comparison and interview cards
Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.








More cards: Ravi Sir's Cards.