Can't edit file after `chattr +i`
Solution 1
chattr -i
will remove immutability, then you can chattr +i
it again afterwards.
EDIT
Based on your lsattr
output, you've also set "append-only". Clear that as well (chattr -a
).
Solution 2
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
.
Solution 3
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.
Related videos on Youtube
fl00r
Updated on September 18, 2022Comments
-
fl00r almost 2 years
After
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.
UPD
ls -l /etc/hosts -rw-r--r-- 1 root root 274 2011-06-09 14:14 /etc/hosts
UPD 2
lsattr /etc/hosts -----a-----------e- /etc/hosts
UPD 3
Thanx, @womble, I've removed
a
attributechattr -a /etc/hosts
-
fl00r almost 13 years@womble
Operation is denied
is my translation of error from my localization. -
womble almost 13 yearsPlease 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. -
fl00r almost 13 years@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. -
womble almost 13 years
LANG=C <command>
will do it. -
fl00r almost 13 years
Operation not permitted
-
-
fl00r almost 13 yearsand 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. -
Janne Pikkarainen almost 13 yearsDid you edit it as root? Or, as in the world of Ubuntu,
sudo <yourtexteditor> /etc/hosts
? -
fl00r almost 13 years@Janne Pikkarainen yep of course :). But it still throws an error
Operation is denied
. -
womble almost 13 yearsAdd more info to your question, not comments. Also, if you've already tried that, why didn't you mention it in your question?
-
fl00r almost 13 yearsQUestion is updated. I can edit other files
-
fl00r almost 13 years@womble, done :)
-
Janne Pikkarainen almost 13 yearsAnd my answer is edited, too.
-
Janne Pikkarainen almost 13 yearsfl00r: 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.