brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: chattr +i makes a file immutable, which normal permissions cannot do for root

Permissions
~/tips/tip-permissions-chattr-immutable-file

sudo chattr +i /srv/app/settings.conf

Locks a file against any change, including by root, until the flag is removed.

Root ignores the write bit, so chmod does not protect a file from root. The immutable attribute does.

sudo chattr +i /srv/app/settings.conf
lsattr /srv/app/settings.conf
sudo chattr -i /srv/app/settings.conf

With +i the file cannot be changed, renamed, deleted or linked, not even by root, until the flag is removed. That stops a script or an installer from overwriting it, and it also blocks your own edits until you run chattr -i. It works on ext4, XFS and Btrfs. Remember it when a file refuses to change: lsattr shows the flag, which ls -l never does.

Further reading: chattr manual page

More Permissions tips sudo su -s /bin/bash www-data sudo setfacl -R -d -m g:media:rwX /srv/media sudo cp -r /srv/site /srv/site.r ls -ln /srv/data newgrp media All Permissions tips (30) All topics

Link