Don't have permission to unlock hosts

Discussion in 'Mac OS X Lion (10.7)' started by helios16v, Jul 3, 2011.

  1. helios16v macrumors regular

    Joined:
    Nov 1, 2008
    Location:
    Earth
    #1
    I'm trying to edit my hosts for anonymous reasons, the method I've been told to use is to open terminal and type:
    Code:
    sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit /etc/hosts
    However that doesn't work so I found that typing:
    Code:
    sudo open -t /etc/hosts
    works fine when I was on 10.7 DP 4, but now that I'm running 10.7 GM the hosts file still opens but now I'm being told that I don't have permission to unlock the hosts file.

    I clicked "Unlock"
    [​IMG]

    Then I get this..
    [​IMG]

    What should I do?
     
  2. Lord Appleseed macrumors 6502a

    Lord Appleseed

    Joined:
    Nov 7, 2010
    Location:
    Apple Manor
    #2
    Very interesting.

    The first command doesn't work for me either but the second does. However i have no problems at all unlocking Hosts.
    You could try repairing Disk Permissions in Disk Utility.
     
  3. helios16v, Jul 3, 2011
    Last edited: Jul 3, 2011

    helios16v thread starter macrumors regular

    Joined:
    Nov 1, 2008
    Location:
    Earth
    #3
    Finished Repairing Disk Permissions, then Verified Disk Permissions, and Restarted. Still cannot unlock the hosts file.

    EDIT:
    Got it! I had to use:
    Code:
    sudo nano /private/etc/hosts
    to edit the hosts file within Terminal, Control-O to save, then hit the Return key and I was golden and ready to go.

    Thanks for trying to help, I hope someone else gets use out of this thread :)
     
  4. Lord Appleseed macrumors 6502a

    Lord Appleseed

    Joined:
    Nov 7, 2010
    Location:
    Apple Manor
    #4
    Awesome, great that it worked out for you.

    But I wonder why i could simply unlock it after using the other command and you couldn't...
     
  5. jocamero macrumors regular

    Joined:
    Jul 11, 2008
    #5
    I had a lot issues getting changes to the hosts file to be recognized on two separate machines, even after flushing the DNS cache using: sudo dscacheutil -flushcache. The only thing I can guess after finally getting this to work is that it has something to do with Lion's file versions and locking the file. Until I noticed the file was 'Locked' automatically by the OS none of my changes were being recognized. Has anyone else had these issues?
     
  6. henry72 macrumors 65816

    henry72

    Joined:
    Jun 18, 2009
    Location:
    New Zealand
    #6
    Thanks a lot. It works for me, I can unlock the "host file". This is the easiest way to edit. ;)

    Cheers man.
     
  7. rmwebs macrumors 68040

    Joined:
    Apr 6, 2007
    #7
    In command line just use this:
    Code:
    sudo nano /etc/hosts
    It'll prompt for your admin password, then it'll let you edit the file.

    When you're done. hit CTRL and X and it'll ask you to press 'y' to confirm you want to save the changes.
     
  8. threesecondmemo macrumors newbie

    Joined:
    Sep 22, 2011
    #8
    I have tried all kinds of ways to try and be able to alter the hosts file in Lion, but no joy with any.

    With the Terminal sudo nano method I get an error when I try to save file saying that "I do not have permission".

    I am an administrator on this macbook.

    Been trying to figure this out for a week now and going around in circles.

    Can anyone think of another way around this?

    Is there a way to overwrite the hosts file with a new one with the exact same name?
     
  9. sidewinder macrumors 68020

    sidewinder

    Joined:
    Dec 10, 2008
    Location:
    Northern California
  10. Watabou macrumors 68040

    Watabou

    Joined:
    Feb 10, 2008
    Location:
    United States
    #10
    Why can't you just Get Info and then unlock the permission from there? No messing about with the terminal. That's what I did to get my hosts file unlocked and it worked for me.
     
  11. mganemx macrumors newbie

    Joined:
    Oct 18, 2011
    Location:
    México
    #11
    Thanks

    Hi
    Your post really work for me.
    Thank you.
     
  12. nckslvrmn macrumors newbie

    Joined:
    Jun 1, 2012
    #12
    you can't unlock hosts because you don't have read/write permissions not just to the file but also to the folder

    by typing

    sudo chown /private/etc

    and then entering root password, you can then unlock the hosts file.

    you might also need to take ownership of the file itself. to do so type in this:

    sudo chown /private/etc/hosts
     
  13. sidewinder macrumors 68020

    sidewinder

    Joined:
    Dec 10, 2008
    Location:
    Northern California
    #13
    Don't do any of this....jeez.

    S-
     
  14. Mal macrumors 603

    Mal

    Joined:
    Jan 6, 2002
    Location:
    Orlando
    #14
    Not only would those commands not work (as they lack at least one important part of the command), but this is a very bad idea. If you change the ownership of the /private/etc folder, you could potentially end up with a non-functioning OS, and at the very least will experience significant problems. This is almost as bad as telling someone to just change permissions for their entire hard drive.

    jW
     
  15. jo88 macrumors newbie

    Joined:
    Jun 12, 2012
    #15
    don't know admin password

    i have a problem when i type sudo nano /private/etc/hosts and then password prompt i don't know my admin password.always wrong.help me pls..
    [​IMG]
    anyone can help me to solve this problem?thx be4
     
  16. iVoid macrumors 65816

    Joined:
    Jan 9, 2007
    #16
    You need to be logged in with a user with admin rights to use sudo.

    (or have an admin user set you up in the sudoers file)
     
  17. chihockey macrumors newbie

    Joined:
    Aug 12, 2012
    Location:
    Arlington Heigths, IL
    #17


    The second command worked for me!! After trying all else.

    Thanks!
     
  18. VideoNewbie, Sep 7, 2012
    Last edited: Sep 7, 2012

    VideoNewbie macrumors 6502

    Joined:
    Feb 6, 2009
    #18


    i did exctly as you said and i pressed "y" to confirm but when i went back and typed in "sudo nano /etc/hosts" under the host to see if the changes were there i dont see anything?

    how do you know if the change actualy went thru? and how do we know if we did it corrrectly? im paranoid about messing up the system unknowingly
     
  19. rwg macrumors newbie

    Joined:
    Sep 8, 2012
    #19
    Oh dear...

    I did this before seeing that it was a bad idea (complete newbie!), have I messed up my system now? If so, what can I do to fix it?

    Thanks!
     
  20. Mal macrumors 603

    Mal

    Joined:
    Jan 6, 2002
    Location:
    Orlando
    #20
    Did you do exactly what was in that post before? If so, you should have simply gotten an error message and the command wouldn't have done anything. If you "correctly" changed the permissions for the /private/etc folder, then you'd want to change it back to what it should be, and the easiest approach would be to simply Repair Permissions in Disk Utility.

    jW
     
  21. VideoNewbie macrumors 6502

    Joined:
    Feb 6, 2009
    #21
    im a bit alarmed by your post...

    i did this:

    did i just mess up my system? i was able to get up to pressing "Y" to confim changes

    but when i went back to look at "sudo nano /etc/hosts" in the terminal none of the changes i made are present...

    does this mean the changes i made did not take into effect?
     
  22. rmwebs macrumors 68040

    Joined:
    Apr 6, 2007
    #22
    Make sure you hit enter after pressing 'y' - read the bottom left of the terminal window and it'll ask you to save (where you press 'y') then you press enter to confirm.
     
  23. Mal macrumors 603

    Mal

    Joined:
    Jan 6, 2002
    Location:
    Orlando
    #23
    No, that's not what I was referring to. That process is fine, it was the suggestion to change the ownership of the /private/etc folder that was dangerous.

    jW
     
  24. internaliserad, Sep 17, 2012
    Last edited: Sep 17, 2012

    internaliserad macrumors newbie

    Joined:
    Sep 17, 2012
    #24
    So I'm new and a bit of..

    I've got my new MacBook Pro Retina with the OS X Mountain Lion. With the risk of repeating and writing with bad English I have to ask the following..

    How come I can't acces the hosts file by writing ( know that there is changes to the new OS X but what are they in relation to this problem and why )?

    sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit /etc/hosts

    What should I do instead to be able to access/unlock/get permission to change the hosts file?

    Very thankful for answer!

    ps. found this:
    http://osxdaily.com/2012/08/07/edit-hosts-file-mac-os-x/
    will it work? saw this a bit higher up but I'm also a bit paranoid about messing
    up the system..?

    Sincerely,
    Internaliserad
     
  25. Mal macrumors 603

    Mal

    Joined:
    Jan 6, 2002
    Location:
    Orlando
    #25
    Your first command will open it, but you won't be able to save it. BTW, "sudo open -t /etc/hosts" would do the same thing much quicker.

    The link you posted has the right method, although I prefer pico over nano (personal preference, though). Shouldn't pose any problems.

    jW
     

Share This Page