OSX 10 Lion hosts file issue

Discussion in 'Mac OS X Lion (10.7)' started by ostatesman, Sep 10, 2011.

  1. ostatesman, Sep 10, 2011
    Last edited: Sep 10, 2011

    macrumors newbie

    Joined:
    Sep 10, 2011
    #1
    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?
     
  2. macrumors newbie

    Joined:
    Sep 18, 2009
    #2
    Have you tried
    Code:
    sudo nano /private/etc/hosts
     
  3. macrumors 6502a

    Joined:
    Dec 31, 2010
    #3
    It seems to be an issue with Lion. Just use Gas Mask to edit the hosts file. Much easier.
     
  4. macrumors demi-goddess

    costabunny

    Joined:
    May 15, 2008
    Location:
    ~/
    #4
    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?
     
  5. macrumors 68020

    killerrobot

    Joined:
    Jun 7, 2007
    Location:
    127.0.0.1
    #5
    +1. In Lion you can no longer edit the file using TextEdit.

    As costabunny says, make sure you're using an admin account.
     
  6. macrumors 6502a

    Asclepio

    Joined:
    Jul 11, 2011
    #6
    +1. In Lion you can no longer edit the file using TextEdit.



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

    killerrobot

    Joined:
    Jun 7, 2007
    Location:
    127.0.0.1
    #7
    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. :)
     
  8. macrumors newbie

    Joined:
    Sep 22, 2011
    #8
    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?
     
  9. r0k
    macrumors 68040

    r0k

    Joined:
    Mar 3, 2008
    Location:
    Detroit
    #9
    I never noticed the problem. I use VI.

    Code:
    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.
     
  10. macrumors 6502a

    Joined:
    Sep 3, 2010
    #10
    works just fine.

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

    Joined:
    Jun 10, 2009
    #11
    +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:

    Code:
    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.
     
  12. Moderator

    maflynn

    Staff Member

    Joined:
    May 3, 2009
    Location:
    Boston
    #12
    I use sudo pico on the host file and that does the job.
     
  13. macrumors newbie

    Joined:
    Sep 29, 2011
    #13
    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!
     
  14. macrumors 65816

    Joined:
    Jul 7, 2011
    #14
    As mentioned you need to open the file under sudo

    It is just a security feature

    Code:
    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
     
  15. macrumors 68020

    sidewinder

    Joined:
    Dec 10, 2008
    Location:
    Northern California
    #15
    Lokheed,

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

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

    S-
     
  16. macrumors newbie

    Joined:
    Sep 29, 2011
    #16
    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). :(
     
  17. macrumors 65816

    Joined:
    Jul 7, 2011
    #17
    You typed it in terminal right?
     
  18. macrumors newbie

    Joined:
    Sep 29, 2011
    #18
    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 :)
     
  19. macrumors newbie

    Joined:
    Sep 29, 2011
    #19
    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
     

Share This Page