PDA

View Full Version : OSX 10 Lion hosts file issue




ostatesman
Sep 10, 2011, 10:24 PM
I am having what appears to be a permissions issue with the hosts file. I can open it via text editor or terminal but can't write it to save the changes I have made.

I have tried using the recommended procedures for dealing with the issue but can't seem to get any to work.

In terminal I get the error [ Error writing /etc/hosts: Operation not permitted ]


despite the fact I used the sudo command to open the file in the first place.

Any ideas?



Janneman59
Sep 11, 2011, 05:36 AM
Have you tried
sudo nano /private/etc/hosts

axu539
Sep 11, 2011, 09:48 AM
I am having what appears to be a permissions issue with the hosts file. I can open it via text editor or terminal but can't write it to save the changes I have made.

I have tried using the recommended procedures for dealing with the issue but can't seem to get any to work.

In terminal I get the error [ Error writing /etc/hosts: Operation not permitted ]


despite the fact I used the sudo command to open the file in the first place.

Any ideas?

It seems to be an issue with Lion. Just use Gas Mask to edit the hosts file. Much easier.

costabunny
Sep 11, 2011, 10:02 AM
works on on both my lions. (just saying so it isnt all lions)

Have you tried opeing a terminal window. 'sudo su -' (change to root user) then 'cd /etc/hosts' followed by 'vi hosts' (replace vi with your chosen editor if you like)...

Does that allow you to save the file?

can you (as root) run an 'ls -la /etc/hosts' and see what it shows?

it should let you open, edit and write with 'sudo nano /etc/hosts' but may changing to root and then editing as superuser will work.

Have you got any AV, Spyware, etc running that might be blocking changes to the hosts file?

killerrobot
Sep 11, 2011, 10:09 AM
It seems to be an issue with Lion. Just use Gas Mask to edit the hosts file. Much easier.

+1. In Lion you can no longer edit the file using TextEdit.


Have you tried opeing a terminal window. 'sudo su -' (change to root user) then 'cd /etc/hosts' followed by 'vi hosts' (replace vi with your chosen editor if you like)...



As costabunny says, make sure you're using an admin account.

Asclepio
Sep 11, 2011, 10:14 AM
+1. In Lion you can no longer edit the file using TextEdit.



Yes you can, just save and duplicate the file without extension.

killerrobot
Sep 11, 2011, 10:18 AM
+1. In Lion you can no longer edit the file using TextEdit.
Yes you can, just save and duplicate the file without extension.

Let me rephrase that - you can no longer use the terminal command to open the host file in textedit, edit it, then save it in one easy process as you could in SL. :)

threesecondmemo
Sep 22, 2011, 05:45 PM
I am having this exact same issue. Any ideas on how to get around it? Tried everything posted so far. Same error.

Could someone talk me through how to do it in GasMask?

r0k
Sep 22, 2011, 10:43 PM
I am having this exact same issue. Any ideas on how to get around it? Tried everything posted so far. Same error.

Could someone talk me through how to do it in GasMask?

I never noticed the problem. I use VI.

cd /private/etc
sudo vi hosts

enter your password when prompted

Inside vi, you start off in command mode. Type i and you are in insert mode. Hit escape after typing (or not typing) and you are back in command mode. :$ puts you at the end of the file. O opens a line above and o opens a line below. i inserts at the cursor and I inserts at the beginning of the current line. A inserts at the end of the current line and a inserts at cursor. :q quits. :q! quits regardless of the fact you might not have saved your work. :wq writes and quits. That's it. You are now a vi user and you can rest assured vi is installed on every Unix box on this planet. No spazzing out while you look for nano, pico or textedit or cough-cough wordpad. VI is just there. Learning a half dozen : commands and learning to tell whether you are in insert or command mode isn't such a high price to pay when you consider you will always have vi.

phyrexia
Sep 23, 2011, 12:04 AM
$ sudo pico /etc/hosts

works just fine.

pico and nano are much less powerful than vi but IMO much easier to use for the newb.

Lokheed
Sep 23, 2011, 01:14 AM
Have you tried
sudo nano /private/etc/hosts

+1. If you can't use command line, you really have no business in there (or at the very least, sudo).

And you don't need anything to open it using Text Editor. Just run TE as root using:

sudo "/Applications/TextEdit.app/Contents/MacOS/TextEdit"

It'll launch. Go to File > Open and you'll be greeted with a nice and open Finder window that doesn't even hide the core folders. So go to etc and then select "hosts". Boom done.

maflynn
Sep 23, 2011, 06:32 AM
I use sudo pico on the host file and that does the job.

DompiE
Sep 29, 2011, 02:28 PM
Hi

I tried everything but i can't edit my hosts file anymore (it worked once 3 weeks ago).
I tried:
- everything through terminal (sudo nano/vi/pico)
- terminal --> /etc/hosts and /private/etc/hosts
- logging in as root and even root can't edit the file

tried costabunny's approach, result:
-rw-r--r--@ 1 root wheel 3678 Sep 4 20:30 /etc/hosts

Is this a privilige question or did i something the first time I edited the hosts file?

Thanks in advance!

bp1000
Sep 29, 2011, 06:21 PM
As mentioned you need to open the file under sudo

It is just a security feature

sudo vi /etc/hosts

Keyboard only....

Press i (this will enter insert mode)

Make your changes / add your ip's hosts etc

then press escape to come out of insert mode

Then just type (you will see at the bottom)

:wq

that will write and quit the file

to quite without saving its, :q!

to write it's just :w

sidewinder
Sep 29, 2011, 07:31 PM
+1. If you can't use command line, you really have no business in there (or at the very least, sudo).

And you don't need anything to open it using Text Editor. Just run TE as root using:

sudo "/Applications/TextEdit.app/Contents/MacOS/TextEdit"

It'll launch. Go to File > Open and you'll be greeted with a nice and open Finder window that doesn't even hide the core folders. So go to etc and then select "hosts". Boom done.

Lokheed,

You can't edit the "/etc/hosts" file with TextEdit anymore.

You have to use "nano" or my personal preference, "vi".

S-

DompiE
Sep 30, 2011, 12:33 AM
As I said i tried everything with sudo. (vi, nano, pico)

but I tried again:

bp1000: vi says: can't write to file (after nagging about its read only). :(

bp1000
Sep 30, 2011, 06:50 AM
As I said i tried everything with sudo. (vi, nano, pico)

but I tried again:

bp1000: vi says: can't write to file (after nagging about its read only). :(

You typed it in terminal right?

DompiE
Sep 30, 2011, 08:36 AM
You typed it in terminal right?
Of course :)

I first thought it's a problem of permissions, but if I'm root (which has al write and read permissions) I can't edit hosts either.

So know I think that the file is maybe in use or something like that, so I can't edit.
Is there a way to see what processes are using hosts atm?

I really don't know it anymore :)

DompiE
Oct 1, 2011, 03:40 AM
Well problem solved...

I did the permission recovery in the disk utility, then the permission check and restart.
then the sudo nano /etc/hosts and it worked.

Really don't know what the problem was... :)


Greetz and thanks for answers