Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

helios16v

macrumors regular
Original poster
Nov 1, 2008
149
0
Earth
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"
ScreenShot2011-07-03at83138AM.jpg


Then I get this..
ScreenShot2011-07-03at83150AM.jpg


What should I do?
 

Lord Appleseed

macrumors 6502a
Nov 7, 2010
682
37
Apple Manor
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.
 

helios16v

macrumors regular
Original poster
Nov 1, 2008
149
0
Earth
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 :)
 
Last edited:

Lord Appleseed

macrumors 6502a
Nov 7, 2010
682
37
Apple Manor
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 :)
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...
 

jocamero

macrumors regular
Jul 11, 2008
161
119
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?
 

rmwebs

macrumors 68040
Apr 6, 2007
3,140
0
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.
 

threesecondmemo

macrumors newbie
Sep 22, 2011
2
0
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?
 

Watabou

macrumors 68040
Feb 10, 2008
3,425
755
United States
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.
 

nckslvrmn

macrumors newbie
Jun 1, 2012
2
0
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
 

sidewinder

macrumors 68020
Dec 10, 2008
2,425
130
Northern California
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

Don't do any of this....jeez.

S-
 

Mal

macrumors 603
Jan 6, 2002
6,252
18
Orlando
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

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
 

jo88

macrumors newbie
Jun 12, 2012
1
0
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..
ScreenShot2012-06-12at221125.png

anyone can help me to solve this problem?thx be4
 

iVoid

macrumors 65816
Jan 9, 2007
1,145
190
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..
Image
anyone can help me to solve this problem?thx be4

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)
 

chihockey

macrumors newbie
Aug 12, 2012
2
0
Arlington Heigths, IL
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"
Image

Then I get this..
Image

What should I do?



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

Thanks!
 

VideoNewbie

macrumors 6502
Feb 6, 2009
476
6
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.



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
 
Last edited:

rwg

macrumors newbie
Sep 8, 2012
1
0
Oh dear...

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

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!
 

Mal

macrumors 603
Jan 6, 2002
6,252
18
Orlando
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!

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
 

VideoNewbie

macrumors 6502
Feb 6, 2009
476
6
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
im a bit alarmed by your post...

i did this:

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.

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?
 

rmwebs

macrumors 68040
Apr 6, 2007
3,140
0
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?

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.
 

Mal

macrumors 603
Jan 6, 2002
6,252
18
Orlando
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?

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
 

internaliserad

macrumors newbie
Sep 17, 2012
3
0
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
 
Last edited:

Mal

macrumors 603
Jan 6, 2002
6,252
18
Orlando
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

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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.