sudo chattr +i /etc/hosts

Category: Administration

sudo chattr +i /etc/hosts

Make a file immutable

The +i flag makes a file completely immutable, so even root cannot modify, rename, or delete it until the flag is removed. This hardens critical files like /etc/hosts or /etc/passwd against accidental edits and malware. Reverse it with sudo chattr -i and list attributes with lsattr.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.