Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

When I try to edit my /etc/hostname file, using sudo nano /etc/hostname (or any other editor) I get the following:

Error writing /etc/hostname: Permission denied

I then tried:

sudo chmod u+w ./hostname

And got the error:

chmod: changing permissions of `./hostname': Operation not permitted

I get the same error trying to add write permissions to any use or group.

This is what ls shows:

-rw-r--r-- 1 root root 22 2012-06-18 12:25 /etc/hostname

Any idea why and what can I do about it?

I'm running Ubuntu 11.10.

share|improve this question
can you plz " cat /etc/hosts ? cat /etc/hostname ? " – One Zero Jun 19 '12 at 1:05
up vote 3 down vote accepted

Sounds like your /etc/hostname file is 'immutable', by way of having the immutable filesystem attribute. You can check with lsattr, and should see something like this:

[jk@pecola ~]$ lsattr /etc/hostname
-------------e- /etc/hostname

if there's an i in there, your file is immutable. You can change this with:

sudo chattr -i /etc/hostname

Then you should be able to edit it.

For more information about filesystem attributes, and the attributes that are available, see the manpage for chattr:

man chattr

This article is also useful.

share|improve this answer

This could be greatly frowned upon, but the following works for me:

$ sudoedit /etc/hostname

We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
share|improve this answer
Why would this be frowned upon? Using sudoedit is one of the good, recommended ways to edit system files owned by root. (On the other hand, given that sudo cannot chmod the file and a nano run by sudo cannot change it, it's very unlikely that this approach will work for this problem. But it's not frowned upon.) – Eliah Kagan Jun 19 '12 at 3:02

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.