LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 03-13-2012, 10:27 AM   #1
Iyyappan
Member
 
Registered: Dec 2008
Location: Chennai, India
Distribution: CentOS 5, SLES 11
Posts: 245

Rep: Reputation: 4
/etc/hosts file is read-only for root in ubuntu Server. But rw- is for root


In my Ubuntu server 10 64bit, /etc/hosts file is read only. Rights of /etc/hosts are
-rw-r--r-- 1 root root 392 2012-03-09 09:55 hosts. But i am unable to edit the file. I do not have gui installed in it. /etc/resolv.conf is editable, but /etc/hosts file alone is not editable. This machine is in OPSource Cloud.

I have logged in as root user only. Kindly help

Last edited by Iyyappan; 03-13-2012 at 10:33 AM.
 
Old 03-13-2012, 12:24 PM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 15,095

Rep: Reputation: 2090Reputation: 2090Reputation: 2090Reputation: 2090Reputation: 2090Reputation: 2090Reputation: 2090Reputation: 2090Reputation: 2090Reputation: 2090Reputation: 2090
Try this (as root)

Quote:
cat > /etc/hosts <<EOF
It will return
>
and you can type in lines and press return (you get another '>') and build up your new /etc/hosts. For the last line just type

>EOF

and it might write it.

The other basic check to run is
cd /etc
touch blah

you should get /etc/blah length zero bytes. That's the acid test of whether you have write permissions.
 
Old 03-14-2012, 04:32 AM   #3
Iyyappan
Member
 
Registered: Dec 2008
Location: Chennai, India
Distribution: CentOS 5, SLES 11
Posts: 245

Original Poster
Rep: Reputation: 4
I did as u said the output is as follows
O/P
> EOF
-bash: /etc/hosts: Permission denied

* i created another file werty in /etc
-rw-r--r-- 1 root root 0 2012-03-14 05:28 werty
i am able to edit the file werty. I am not able to edit /etc/host file alone.....

Any other ideas....
 
Old 03-14-2012, 06:02 AM   #4
deep27ak
Senior Member
 
Registered: Aug 2011
Location: Bangalore, India
Distribution: RHEL 7.x, SLES 11 SP2/3/4
Posts: 1,195
Blog Entries: 4

Rep: Reputation: 221Reputation: 221Reputation: 221
copy the contents of /etc/hosts file into a new file with same permission 644
Code:
#cp /etc/hosts /etc/hosts.bak <--take backup

#vi /etc/hosts1 <--create a new file
paste the lines from hosts file

#mv /etc/hosts1 /etc/hosts
 
Old 03-14-2012, 06:59 AM   #5
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
What does:
Code:
$ lsattr /etc/hosts
show?
 
Old 03-14-2012, 08:31 AM   #6
Iyyappan
Member
 
Registered: Dec 2008
Location: Chennai, India
Distribution: CentOS 5, SLES 11
Posts: 245

Original Poster
Rep: Reputation: 4
@Deepak
mv: cannot move `/etc/hosts1' to `/etc/hosts': Operation not permitted


@Reuti
lsattr /etc/hosts
O/P ==----i------------e- /etc/hosts

Interestingly lsattr /etchosts1 is
O/P -----------------e- /etc/hosts1

Last edited by Iyyappan; 03-14-2012 at 08:35 AM.
 
Old 03-14-2012, 08:36 AM   #7
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
Aha, then we have to change the immutable bit (see man chattr):
Code:
$ chattr -i /etc/hosts
Then it should be possible to work on it again.
 
1 members found this post helpful.
Old 03-14-2012, 08:44 AM   #8
Iyyappan
Member
 
Registered: Dec 2008
Location: Chennai, India
Distribution: CentOS 5, SLES 11
Posts: 245

Original Poster
Rep: Reputation: 4
Done it worked great.....thanks. How did the attributes got changed. This was a new machine created in cloud. Is there any scenario under which this change occurs? But i have not done any change to system related files

Last edited by Iyyappan; 03-14-2012 at 08:46 AM.
 
Old 03-14-2012, 08:51 AM   #9
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
Was it installed by the provider or by you? I would assume that it was set up during installation to avoid that a bad setup could make the access to the machine impossible.

The only thing I wonder about now: the “e” showing up in your output. I don’t have it anywhere, and it’s also not explained in chattr man page. Is it explained in your version of the man page?
 
Old 03-14-2012, 08:59 AM   #10
Iyyappan
Member
 
Registered: Dec 2008
Location: Chennai, India
Distribution: CentOS 5, SLES 11
Posts: 245

Original Poster
Rep: Reputation: 4
Machine was created from an image hosted in Op source Cloud. It was created and hosted as an image by third party. May be he has changed the attributes after installation and then took an image of it and hosted in Cloud

Man Page:

The 'e' attribute indicates that the file is using extents for mapping the blocks on disk. It may not be removed using chattr(1).


The 'e' was not removed when i gave chattr command. 'e' is found in Ubuntu Server 10 alone. But not in CentOS

Last edited by Iyyappan; 03-14-2012 at 09:04 AM.
 
Old 03-14-2012, 09:02 AM   #11
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
Thx for posting the relevant information.
 
Old 10-01-2013, 01:45 AM   #12
GoldenPaul27
LQ Newbie
 
Registered: Oct 2013
Posts: 1

Rep: Reputation: Disabled
Thumbs down Tried "chattr -i /etc/hosts" in terminal but it didn't work.

Code:
chattr -i /etc/hosts
This code gave me this error:
Code:
chattr: Permission denied while setting flags on /etc/hosts
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Resetting Root Password with File Sharing Server on Ubuntu trojan92 Linux - Server 1 11-28-2011 10:02 AM
[SOLVED] how can i remount root filesystem as read/write after modify readonly-root file jcwkyl Linux - Newbie 3 12-21-2010 10:40 PM
Make a file read-only... even for root Virchanza Linux - General 9 06-03-2010 08:39 PM
read only root file system santhosh.bachu Linux - Software 2 08-22-2006 06:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration