Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

chattr

Set or remove file attributes, like immutable (no change at all) and append only.

Niveau
Dagelijks Linux
Groep
Rechten
Root nodig
Ja
Pakket
e2fsprogs

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

Attributes work below the normal permissions. A file with +i (immutable) cannot be changed, deleted, renamed or linked — not even by root — until the attribute is removed with chattr -i. With +a you can only add data at the end.

Only root (with the right capability) can set i and a. Support depends on the file system: ext4 knows many attributes; XFS supports a smaller set (like i, a, d, S, A, s… only some).

Zo schrijf je het

chattr [-RVf] [-v VERSION] [-p PROJECT] [+-=ATTRIBUTES] FILE...

Belangrijkste delen

+ - =
Add, remove, set exactly.
i
Immutable: no change, delete, rename, link.
a
Append only: only add data (good for logs).
A
Do not update the access time.
d
Skip the file in dump backups.
S
Write changes to disk at once (synchronous).
c
Compress (some file systems).
C
No copy-on-write (btrfs).
e
The file uses extents (ext4, cannot be removed).
u, s
Undeletable / secure delete (not used by ext4).

Opties 5

Meest gebruikt

-R
Change directories and their content recursively.
-V
Verbose; also show the version.
-f
Do not show most errors.
-v VERSION
Set the version/generation number.
-p PROJECT
Set the project number (for project quotas).

Voorbeelden 10

$ als gewone gebruiker# als root (of met sudo)

  1. 1Protect a file against every change

    chattr +i /etc/resolv.conf

    Stops tools (and people) from changing DNS settings.

  2. 2Show the attributes

    lsattr /etc/resolv.conf
    ----i----------------- /etc/resolv.conf

    The i is set.

  3. 3Even root cannot delete it

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

    Remove the attribute first.

  4. 4Remove the protection

    chattr -i /etc/resolv.conf

    Now normal permissions count again.

  5. 5Make a log file append only

    chattr +a /var/log/app/audit.log

    An attacker cannot delete old lines (but can add new ones).

  6. 6Protect important files against ransomware or mistakes

    chattr -R +i /srv/archive/2025

    Old data that must never change.

  7. 7Find immutable files when a change fails

    lsattr -R /etc 2>/dev/null | grep -- '-i-'

    "Operation not permitted" as root often means i.

  8. 8Check for attacker tricks (security)

    lsattr /etc/passwd /etc/shadow /root/.ssh/authorized_keys

    Attackers set +i on their backdoor files so admins cannot remove them.

  9. 9No access time updates for a busy file

    chattr +A /srv/cache/data.db

    Fewer writes (most systems use relatime anyway).

  10. 10Set exactly these attributes

    chattr =a /var/log/app/audit.log

    Removes all others.

Let op

  • An immutable file breaks updates: package updates and config tools fail on it. Document where you use it.
  • Not all file systems support all attributes ("Operation not supported").

Exitcodes

0Done.
1Error.

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man chattr