-1

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 attribute

chattr -a /etc/hosts
6
  • 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, 2011 at 8:21
  • @womble Operation is denied is my translation of error from my localization.
    – fl00r
    Aug 11, 2011 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, 2011 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, 2011 at 8:30
  • 3
    LANG=C <command> will do it.
    – womble
    Aug 11, 2011 at 8:30

3 Answers 3

2

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).

5
  • 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, 2011 at 8:13
  • Did you edit it as root? Or, as in the world of Ubuntu, sudo <yourtexteditor> /etc/hosts? Aug 11, 2011 at 8:15
  • @Janne Pikkarainen yep of course :). But it still throws an error Operation is denied.
    – fl00r
    Aug 11, 2011 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, 2011 at 8:21
  • @womble, done :)
    – fl00r
    Aug 11, 2011 at 8:23
1

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.

3
  • QUestion is updated. I can edit other files
    – fl00r
    Aug 11, 2011 at 8:23
  • And my answer is edited, too. Aug 11, 2011 at 8:27
  • 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. Aug 11, 2011 at 8:34
1

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.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .