Thursday, April 25, 2024
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 22033  / 2 Years ago, mon, august 29, 2022, 3:24:22

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.


More From » command-line

 Answers
4

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.


[#37478] Tuesday, August 30, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ongdiligenc

Total Points: 452
Total Questions: 111
Total Answers: 107

Location: Ukraine
Member since Sun, Dec 13, 2020
3 Years ago
;