Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


chattr +i /etc/hosts

I can't edit this file (obviously). But how can I revert it back. I need to edit this file and then lock again.


ls -l /etc/hosts
-rw-r--r-- 1 root root 274 2011-06-09 14:14 /etc/hosts


lsattr /etc/hosts
-----a-----------e- /etc/hosts


Thanx, @womble, I've removed a attribute

chattr -a /etc/hosts
share|improve this question
lsattr /etc/hosts would be useful to see. Also, "Operation is denied" is not the usual error message you'd expect to see for a permissions problem; I suspect something else is wrong. – womble Aug 11 '11 at 8:21
@womble Operation is denied is my translation of error from my localization. – fl00r Aug 11 '11 at 8:24
Please don't do your own translations; get error messages in the C locale and post them directly -- exact wording can be critical in diagnosing what's gone wrong. – womble Aug 11 '11 at 8:28
@womble, Thank you! I don't know how can I switch locale for only one command (it is system-wide). I can switch to English in whole system only. – fl00r Aug 11 '11 at 8:30
LANG=C <command> will do it. – womble Aug 11 '11 at 8:30
up vote 2 down vote accepted

chattr -i will remove immutability, then you can chattr +i it again afterwards.


Based on your lsattr output, you've also set "append-only". Clear that as well (chattr -a).

share|improve this answer
and what if not? It is still denied to edit. I've tried it already before I wrote my question. Looks like something is messed in permissions to this file. – fl00r Aug 11 '11 at 8:13
Did you edit it as root? Or, as in the world of Ubuntu, sudo <yourtexteditor> /etc/hosts? – Janne Pikkarainen Aug 11 '11 at 8:15
@Janne Pikkarainen yep of course :). But it still throws an error Operation is denied. – fl00r Aug 11 '11 at 8:18
Add more info to your question, not comments. Also, if you've already tried that, why didn't you mention it in your question? – womble Aug 11 '11 at 8:21
@womble, done :) – fl00r Aug 11 '11 at 8:23

I guess you have (accidentally|purposely) made your /etc immutable as well. Try chattr -i /etc as well. If that was not the case, please fill your question more. Give us stat /etc and stat /etc/hosts as well as lsattr /etc/hosts.

Can you modify any other file under /etc?

EDIT after your own edit: You have a attribute set for /etc/hosts. That means you can only append to that file, every other write operation is denied. Try chattr -a /etc/hosts.

share|improve this answer
QUestion is updated. I can edit other files – fl00r Aug 11 '11 at 8:23
And my answer is edited, too. – Janne Pikkarainen Aug 11 '11 at 8:27
Thanks. I am not sure how it happened :) – fl00r Aug 11 '11 at 8:31
fl00r: Don't be shy, we can all guess how it happened. Enough administrative beer and a willingness to harden your server can lead to interesting situations. – Janne Pikkarainen Aug 11 '11 at 8:34

The a attribute makes your file append-only, use chattr -a to remove it. See man 1 chattr to see what all other attribute flags are are.

share|improve this answer
Thank you, I'll read it now – fl00r Aug 11 '11 at 8:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.