Ravindra BagaleCourses & study guides मराठी Track your progress

Linux ACL and File Attributes: setfacl, getfacl, chattr and lsattr with Examples

Normal permissions give rights to one owner, one group and everyone else. Sometimes you need more: give one extra user read access, or give two teams different rights on the same folder. ACLs (Access Control Lists) do that. File attributes (chattr) add another layer: a file can be made immutable so even root cannot change it, or append-only for logs.

What you'll learn in this chapter

  • Know when ACLs are needed
  • Read ACLs with getfacl and spot the + in ls -l
  • Add, change and remove ACLs with setfacl
  • Use default ACLs and understand the mask
  • Keep ACLs during copy, backup and restore
  • Use lsattr and chattr +i / +a

1. An everyday example: a housing society notice room

Why do we need this?

In a Kothrud society, the office room belongs to the secretary and the committee. The plumber also needs to enter on Tuesdays, but he is not on the committee. Instead of adding him to the committee, the secretary writes his name on a special list at the door: 'Plumber: may enter, may not touch files'. The society rule book is laminated and locked in glass: nobody can change it, not even the secretary, until the glass is unlocked. The visitor register only allows new lines; old lines cannot be erased.

What is it?

Owner and group = secretary and committee. Special list at the door = ACL. 'May enter, may not touch' = r-x for one user. Locked glass = chattr +i (immutable). Visitor register = chattr +a (append-only).

How to do it (step by step)

How Linux checks a file with an ACLIs the process the owner? Use owner bitsIs there a named user entry for it? Use it, limited by maskDoes a group or named group match? Use the best one, limited by maskElse use other bitsThen attributes: +i blocks all changes, +a allows only appendingFinally SELinux/AppArmor may still say no
The mask is the ceiling for named users and all groups.

2. Why ACLs: limits of owner/group/other

Why do we need this?

A file has only one group. If finance needs read and audit needs read-write on the same folder, normal bits cannot do it without messy groups.

What is it?

ACLs add extra entries: user:NAME:rwx and group:NAME:rwx, plus a mask and defaults for new files. They work on ext4, XFS and most modern file systems (mounted with acl, which is the default). A + at the end of ls -l mode means an ACL exists.

How to do it (step by step)

  1. Spot an ACL.
ls -ld /srv/reports

Output:

drwxrwx---+ 2 ravi finance 4096 Oct 25 /srv/reports

What it means: The + means there is more than the 9 bits.

  1. Is the tool installed?
command -v setfacl getfacl || sudo dnf install -y acl

Output:

/usr/bin/setfacl
/usr/bin/getfacl

What it means: Package name is acl.

3. getfacl: read an ACL

Why do we need this?

Before changing or debugging access you must see every entry, including the mask.

What is it?

getfacl FILE prints owner, group, then user::, user:NAME:, group::, group:NAME:, mask::, other::, and default: lines for folders. '#effective:' shows rights cut by the mask. -R walks a tree. -c hides the header.

How to do it (step by step)

  1. Read a folder ACL.
getfacl /srv/reports

Output:

# file: srv/reports
# owner: ravi
# group: finance
user::rwx
user:priya:r-x
group::rwx
group:audit:rwx
mask::rwx
other::---

What it means: priya can read, audit can write.

  1. Without header.
getfacl -c /srv/reports/q3.csv

Output:

user::rw-
user:priya:r--
group::r--
mask::r--
other::---

What it means: Short and easy to compare.

  1. An effective right cut by the mask.
getfacl -c data.csv | grep effective

Output:

user:sam:rw-		#effective:r--

What it means: sam's w is blocked by the mask.

4. setfacl -m: add or change an entry

Why do we need this?

Give one more person or team access without changing the owner, group or other bits.

What is it?

setfacl -m u:NAME:rwx FILE for a user, -m g:NAME:rx for a group, -m o::- for others. Several at once with commas. -R for a tree (use X to give x only on folders). The mask updates automatically.

How to do it (step by step)

  1. Let priya read one file.
setfacl -m u:priya:r q3.csv && getfacl -c q3.csv | grep priya

Output:

user:priya:r--

What it means: No group change needed.

  1. Give the audit team write.
setfacl -m g:audit:rw q3.csv && ls -l q3.csv

Output:

-rw-rw----+ 1 ravi finance 9K Oct 25 q3.csv

What it means: The group bits shown are now the mask.

  1. Whole tree, folders get x.
setfacl -R -m g:audit:rX /srv/reports

Output:

(no output)

What it means: Files are r, folders r-x.

  1. Let nginx pass through a home folder.
setfacl -m u:nginx:x /home/ravi

Output:

(no output)

What it means: Only x: it can reach public_html but cannot list home.

5. Default ACLs: rules for new files

Why do we need this?

Without defaults, new files in a shared folder get no ACL and the extra team loses access.

What is it?

A default ACL on a folder (setfacl -d -m or -m d:...) is copied to new files and sub-folders created inside. It does not change existing files, so pair it with -R -m for those. Only folders can have defaults.

How to do it (step by step)

  1. Set a default for audit.
setfacl -d -m g:audit:rX /srv/reports && getfacl -c /srv/reports | grep default

Output:

default:user::rwx
default:group::rwx
default:group:audit:r-x
default:mask::rwx
default:other::---

What it means: Future files get audit access.

  1. Check a new file.
touch /srv/reports/q4.csv && getfacl -c /srv/reports/q4.csv | grep audit

Output:

group:audit:r-x		#effective:r--

What it means: Inherited; files do not get x.

  1. Existing plus future in two steps.
setfacl -R -m g:audit:rX /srv/reports && setfacl -R -d -m g:audit:rX /srv/reports

Output:

(no output)

What it means: Common pattern for shared folders.

6. The ACL mask

Why do we need this?

People add rw for a user and it still fails. Usually the mask is lower, often after a chmod.

What is it?

mask:: is the maximum right for named users, named groups and the owning group. When a file has an ACL, chmod g=... changes the mask, not the group. setfacl -m m::rwx sets it. setfacl -n stops automatic mask recalculation.

How to do it (step by step)

  1. chmod shrinks the mask.
chmod 640 q3.csv && getfacl -c q3.csv | grep -E 'audit|mask'

Output:

group:audit:rw-		#effective:r--
mask::r--

What it means: audit lost write.

  1. Restore the mask.
setfacl -m m::rw q3.csv && getfacl -c q3.csv | grep mask

Output:

mask::rw-

What it means: audit can write again.

7. setfacl -x and -b: remove entries

Why do we need this?

When a contractor leaves or a test is over, remove the extra access cleanly.

What is it?

setfacl -x u:NAME FILE removes one user entry, -x g:NAME a group entry. -k removes all default entries. -b removes the whole ACL and leaves only normal bits. -R for trees.

How to do it (step by step)

  1. Remove priya.
setfacl -x u:priya q3.csv && getfacl -c q3.csv | grep -c priya

Output:

0

What it means: Her extra access is gone.

  1. Remove defaults only.
setfacl -k /srv/reports

Output:

(no output)

What it means: Existing entries stay.

  1. Remove all ACLs from a tree.
setfacl -R -b /srv/old && ls -ld /srv/old

Output:

drwxrwx--- 2 ravi finance 4096 /srv/old

What it means: The + is gone.

8. Copy, back up and restore ACLs

Why do we need this?

A plain cp or tar can silently drop ACLs, and after a restore people lose access.

What is it?

cp -a (or --preserve=all) keeps ACLs. rsync -aAX keeps ACLs and xattrs. tar --acls --xattrs on create and extract. getfacl -R > file saves them; setfacl --restore=file puts them back. Copy one file's ACL to another: getfacl a | setfacl --set-file=- b.

How to do it (step by step)

  1. Save ACLs of a tree.
getfacl -R /srv/reports > /root/reports.acl && wc -l /root/reports.acl

Output:

58 /root/reports.acl

What it means: A text backup of rights.

  1. Restore them.
cd / && setfacl --restore=/root/reports.acl

Output:

(no output)

What it means: Paths are relative to /.

  1. rsync with ACLs.
rsync -aAX /srv/reports/ backup:/srv/reports/

Output:

(no output)

What it means: A = ACLs, X = xattrs.

  1. tar with ACLs.
tar --acls --xattrs -czf reports.tgz /srv/reports

Output:

(no output)

What it means: Use --acls again when extracting.

9. lsattr: list file attributes

Why do we need this?

A file that even root cannot delete is usually immutable. lsattr shows it.

What is it?

lsattr FILE shows attribute letters: i immutable, a append-only, e extents (normal on ext4), A no atime update, d no dump. lsattr -d FOLDER for the folder itself, -R recursive. Works best on ext4; XFS supports i and a.

How to do it (step by step)

  1. Normal file.
lsattr notes.txt

Output:

--------------e------- notes.txt

What it means: Only e: normal ext4 file.

  1. Immutable file.
lsattr /etc/resolv.conf

Output:

----i---------e------- /etc/resolv.conf

What it means: Someone locked it.

  1. Find all immutable files in /etc.
sudo lsattr -R /etc 2>/dev/null | grep -- '-i-'

Output:

----i---------e------- /etc/resolv.conf

What it means: Useful after 'cannot modify' errors.

10. chattr +i: make a file immutable

Why do we need this?

Stop accidental or automatic changes to a critical file (for example DNS config overwritten by a tool).

What is it?

sudo chattr +i FILE: nobody, including root, can write, delete, rename or link it until chattr -i. Only root (CAP_LINUX_IMMUTABLE) can set or clear it. On a folder, no files can be added or removed inside.

How to do it (step by step)

  1. Lock the file.
sudo chattr +i /etc/resolv.conf && lsattr /etc/resolv.conf

Output:

----i---------e------- /etc/resolv.conf

What it means: Locked.

  1. Even root is refused.
sudo rm /etc/resolv.conf

Output:

rm: cannot remove '/etc/resolv.conf': Operation not permitted

What it means: Permissions are fine; the attribute blocks it.

  1. Unlock to edit.
sudo chattr -i /etc/resolv.conf && sudo vi /etc/resolv.conf

Output:

(editor opens)

What it means: Lock again after editing.

11. chattr +a: append-only

Why do we need this?

Logs should grow but never be edited or truncated, even by an attacker who got a service account.

What is it?

sudo chattr +a FILE: data can only be added at the end (>>). Overwrite (>), truncate and delete fail. Log rotation must clear it first (chattr -a) or use a postrotate step.

How to do it (step by step)

  1. Make a log append-only.
sudo chattr +a /var/log/audit-trail.log && lsattr /var/log/audit-trail.log

Output:

-----a--------e------- /var/log/audit-trail.log

What it means: a is set.

  1. Appending works.
echo 'login ravi' | sudo tee -a /var/log/audit-trail.log

Output:

login ravi

What it means: New line added.

  1. Overwriting fails.
echo x | sudo tee /var/log/audit-trail.log

Output:

tee: /var/log/audit-trail.log: Operation not permitted

What it means: History is safe.

12. Real examples from many industries

Why do we need this?

The same Linux skill shows up in every kind of company. Seeing it in many places helps you remember it.

What is it?

Each row is a made-up team. It shows who uses this and how.

How to do it (step by step)

Team and cityHow they use itCommand
Pooja, CA firm, PuneGives one auditor read access to a client foldersetfacl -R -m u:auditor:rX /srv/clients/acme
Lars, media house, StockholmDefault ACL so editors keep access to new videossetfacl -d -m g:editors:rwX /srv/media
Fatima, hospital, DubaiAppend-only access logchattr +a /var/log/emr-access.log
Diego, ISP, Mexico CityLocks resolv.conf against DHCP overwritechattr +i /etc/resolv.conf
Arjun, backup admin, ChennaiKeeps ACLs in nightly rsyncrsync -aAX /srv/ nas:/backup/srv/
Mia, web host, SydneyLets nginx enter a home folder without listing itsetfacl -m u:nginx:x /home/mia

13. Common errors and how to fix them

Why do we need this?

Everyone hits these errors. Knowing the cause saves hours.

What is it?

Read the exact message first. Then match it to a row below.

How to do it (step by step)

Error you seeWhy it happensHow to fix
setfacl: command not foundacl package missingInstall acl.
sudo dnf install -y acl
setfacl: q3.csv: Operation not supportedFile system without ACL support (some FUSE, NFSv3 without acl)Use a supported fs or mount option acl.
findmnt -no FSTYPE,OPTIONS --target q3.csv
setfacl: Option -m: Invalid argument near character 3Wrong syntax, e.g. u-priya:rUse u:NAME:PERMS.
setfacl -m u:priya:r q3.csv
setfacl: Option -m: Invalid argument near character 3 (unknown user)The user name does not existCheck with id.
id priya
User has ACL rw but still cannot write (#effective:r--)Mask lowered, often by chmodRaise the mask.
setfacl -m m::rw q3.csv
New files in shared folder lack team accessNo default ACLAdd a default ACL.
setfacl -d -m g:audit:rX /srv/reports
ACLs lost after copy or restorecp/tar without ACL optionsUse cp -a, rsync -aAX, tar --acls.
rsync -aAX src/ dst/
rm: cannot remove 'x': Operation not permitted (as root)File is immutableCheck and clear the attribute.
lsattr x && sudo chattr -i x
logrotate: error renaming /var/log/app.log: Operation not permittedAppend-only or immutable logClear +a before rotation, set again after.
sudo chattr -a /var/log/app.log
chattr: Operation not permitted while setting flagsNot root, or inside a container without the capabilityRun as root on the host.
sudo chattr +i file

14. Troubleshooting step by step

Why do we need this?

If access is strange, check normal bits, then ACL and mask, then attributes, then SELinux.

What is it?

Go top to bottom. Stop at the first step that shows the problem.

How to do it (step by step)

  1. See the bits and the +.
ls -l file
  1. Read the full ACL and effective rights.
getfacl file
  1. Check the parent folders too.
namei -l /path/to/file
  1. Look for i or a attributes.
lsattr file
  1. Check the file system supports ACLs.
findmnt -T file
  1. Check SELinux last.
ls -Z file

15. Lab 1: Two teams, one folder

Why do we need this?

finance owns /srv/reports; audit gets read-only on existing and future files; one contractor gets temporary read.

What is it?

A full hands-on lab. Run every step on a test Linux machine (an EC2 instance, a VM, or WSL).

How to do it (step by step)

  1. Set up groups and folder.
sudo groupadd -f finance; sudo groupadd -f audit; sudo useradd -m -G audit aud1; sudo useradd -m contr1; sudo mkdir -p /srv/reports && sudo chgrp finance /srv/reports && sudo chmod 2770 /srv/reports

Output:

(no output)
  1. Give audit read now and later.
sudo setfacl -R -m g:audit:rX /srv/reports && sudo setfacl -d -m g:audit:rX /srv/reports

Output:

(no output)
  1. Create a file and test audit.
echo total=100 | sudo tee /srv/reports/q4.txt >/dev/null && sudo -u aud1 cat /srv/reports/q4.txt && sudo -u aud1 sh -c 'echo x >> /srv/reports/q4.txt'

Output:

total=100
sh: /srv/reports/q4.txt: Permission denied
  1. Give the contractor read.
sudo setfacl -m u:contr1:rx /srv/reports && sudo setfacl -m u:contr1:r /srv/reports/q4.txt && sudo -u contr1 cat /srv/reports/q4.txt

Output:

total=100
  1. Remove the contractor.
sudo setfacl -x u:contr1 /srv/reports /srv/reports/q4.txt && sudo -u contr1 ls /srv/reports

Output:

ls: cannot open directory '/srv/reports': Permission denied

16. Lab 2: Protect files with chattr

Why do we need this?

Make one file immutable and one log append-only, prove it, then undo.

What is it?

A full hands-on lab. Run every step on a test Linux machine (an EC2 instance, a VM, or WSL).

How to do it (step by step)

  1. Create test files.
sudo mkdir -p /srv/lab16 && echo v1 | sudo tee /srv/lab16/conf >/dev/null && echo start | sudo tee /srv/lab16/log >/dev/null

Output:

(no output)
  1. Set attributes.
sudo chattr +i /srv/lab16/conf && sudo chattr +a /srv/lab16/log && lsattr /srv/lab16

Output:

----i---------e------- /srv/lab16/conf
-----a--------e------- /srv/lab16/log
  1. Try to change conf.
echo v2 | sudo tee /srv/lab16/conf

Output:

tee: /srv/lab16/conf: Operation not permitted
  1. Append and overwrite log.
echo line2 | sudo tee -a /srv/lab16/log; echo wipe | sudo tee /srv/lab16/log

Output:

line2
tee: /srv/lab16/log: Operation not permitted
  1. Undo and clean.
sudo chattr -i /srv/lab16/conf && sudo chattr -a /srv/lab16/log && sudo rm -r /srv/lab16

Output:

(no output)

Ravindra Bagale's Tip

When you add an ACL to a shared folder, always add the same rule as a default ACL too (-d), and check '#effective' in getfacl. Most 'ACL does not work' cases are a missing default or a low mask.

17. Frequently asked questions

Q. What does the + in ls -l mean?

The file has an ACL.

Q. Do ACLs replace normal permissions?

No, they add to them. Owner and other bits still apply.

Q. Why does chmod break my ACL?

On a file with an ACL, chmod's group digit sets the mask, which can cut named entries.

Q. Can root bypass chattr +i?

Not without removing the attribute first with chattr -i.

Q. Do ACLs work on NFS and in containers?

NFSv4 has its own ACLs (nfs4_setfacl); container bind mounts keep the host fs ACLs.

Q. Does Windows-style deny exist?

Not in POSIX ACLs. Give fewer rights instead, for example u:sam:---.

Q. Why does chattr fail on XFS for some letters?

XFS supports only some flags (like i and a). Others are ext4-only.

Q. How do I back up ACLs?

getfacl -R > file, or rsync -aAX, or tar --acls.

18. Interview questions and answers

Beginner level

Q. What is an ACL?

An extra list of user and group rights on a file beyond owner/group/other.

Q. How do you read an ACL?

getfacl FILE.

Q. Give user priya read on a file.

setfacl -m u:priya:r FILE.

Q. What does chattr +i do?

Makes a file immutable, even for root.

Mid level level

Q. What is a default ACL?

An ACL on a folder that new files and folders inside inherit.

Q. What is the ACL mask?

The maximum rights for named users, named groups and the owning group.

Q. How do you copy files keeping ACLs?

cp -a, rsync -aAX or tar --acls --xattrs.

Q. chattr +a vs +i?

+a allows only appending; +i allows no change at all.

Senior level

Q. A user has an ACL entry rwx but gets Permission denied. Debug it.

Check #effective (mask), a parent folder's x, the owner entry taking priority, lsattr flags, SELinux, and whether the fs supports ACLs.

Q. Groups vs ACLs: when do you choose which?

Groups for stable role-based access; ACLs for exceptions or multiple teams with different rights on the same tree. Too many ACLs are hard to audit.

Q. Could an attacker with root defeat chattr +a logs?

Yes, root can clear the flag, so ship logs off the box (remote syslog/SIEM) as well.

Q. How do you migrate a share and keep all rights?

rsync -aAXH --numeric-ids, same UIDs/GIDs on both sides, then compare getfacl -R outputs.

Try at home

  1. Create a folder where your friend user can read but not write, without adding them to any group. Prove it with getfacl and a write test.
  2. Make a file immutable, try to delete it as root, then unlock and delete.

Practice Tasks

About this scenario

Amravati Agro Market is a agriculture business in Amravati. Anjali Thakre looks after its IT and cloud work. They count money in INR and run their AWS resources in the ap-south-1 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 / 17

Easy Read an ACL

Why: ls shows a +.

What to do: Show the ACL of /srv/ledger.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy User read access

Why: Auditor visiting BIZ.

What to do: Give user kavya read on q4.csv with an ACL.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy See attributes

Why: Root cannot delete a file.

What to do: List the attributes of /etc/hostname.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium ACL without header

Why: Compare two files easily.

What to do: Show the ACL of q4.csv without the comment header.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Group write access

Why: Audit team edits the file.

What to do: Give group compliance read and write on q4.csv with an ACL.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Whole tree, folders get x

Why: Existing files need access.

What to do: Recursively give group compliance rX on /srv/ledger.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Default ACL for new files

Why: New files must keep access.

What to do: Set a default ACL on /srv/ledger giving group compliance rX.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Remove one user

Why: Contractor left BIZ.

What to do: Remove the ACL entry of user contr1 from q3.csv.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Remove all ACLs

Why: Reset a folder.

What to do: Remove every ACL entry from old.txt.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Copy with ACLs

Why: Nightly backup at BIZ.

What to do: Copy /srv/data/ to /backup/data/ with rsync keeping ACLs and xattrs (archive mode).

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Make immutable

Why: Stop tools overwriting DNS config.

What to do: Make /etc/hostname immutable.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Unlock an immutable file

Why: You need to edit it now.

What to do: Remove the immutable attribute from /etc/hostname.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Append-only log

Why: Audit trail must not be edited.

What to do: Make /var/log/payments.log append-only.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Hard Raise the mask

Why: #effective shows r-- after chmod.

What to do: Set the ACL mask of q4.csv to rw.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Hard Remove default ACLs only

Why: Existing entries must stay.

What to do: Remove only the default ACL of /srv/ledger.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Hard Back up ACLs to text

Why: Before a migration.

What to do: Save the ACLs of /srv/reports recursively into reports.acl.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Hard Let caddy pass through home

Why: Serve ~/public_html without opening home.

What to do: Give user caddy only execute on /home/meera with an ACL.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

In short

  1. + in ls -l means an ACL.
  2. getfacl reads, setfacl -m adds, -x/-b removes.
  3. Default ACLs (-d) for new files.
  4. Mask caps named entries; chmod can change it.
  5. Keep ACLs with cp -a, rsync -aAX, tar --acls.
  6. lsattr shows; chattr +i locks, +a append-only.

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.

ACLs in 4 steps. Give one more user access. setfacl -m adds, getfacl reads. Add -d so new files inherit. Read access for one user.
Revision card: ACLs in 4 steps · Download PNG · Open card page
chattr locks. Even root cannot change it. +i immutable, +a append only. lsattr shows the flags. Protect DNS config.
Revision card: chattr locks · Download PNG · Open card page
chmod vs setfacl. Owner, one group, others. / Any number of users and groups.
Comparison: chmod vs setfacl · Download PNG · Open card page
chattr +i vs chattr +a. Nothing: no write, delete, rename. / Only adding to the end.
Comparison: chattr +i vs chattr +a · Download PNG · Open card page
What is the + in ls -l?. The file has an ACL. chmod may not show all access. Read it.
Interview card: What is the + in ls -l? · Download PNG · Open card page
What is the ACL mask?. Max rights for named entries. chmod on group changes the mask. Raise it.
Interview card: What is the ACL mask? · Download PNG · Open card page
New files lose access?. Normal ACLs apply to existing files. Default ACLs pass to new files. Set default.
Interview card: New files lose access? · Download PNG · Open card page
Root cannot delete a file?. It may be immutable. lsattr shows i. Remove the flag.
Interview card: Root cannot delete a file? · Download PNG · Open card page

More cards: Ravi Sir's Cards.