New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus • Advice and insight from world-class Apple enthusiasts • Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Operating System General OS operation information and support

Tip: Unlocking Hosts file in Lion


Post Reply New Thread Subscribe

 
Thread Tools
Shikarnov

 
Shikarnov's Avatar
 
Member Since: Feb 26, 2008
Posts: 542
Shikarnov is a jewel in the roughShikarnov is a jewel in the roughShikarnov is a jewel in the rough

Shikarnov is offline
Hi All,

As my job involves developing websites, I spend a LOT of time in my hosts file adding domain names that point to my local server, and etc.

Well, after upgrading to Lion, I found that my hosts file (which I keep as an alias on my dock) opened in TextEdit instead of TextMate, like I had it set to open with in Snow Leopard. "No matter," I thought, "I'll just edit in TextEdit and go on with my day."

So I edited, but it wouldn't save. Of course, Lion locked the hosts file, which I suppose shouldn't have been unexpected. What was unexpected was that the Get Info pane wouldn't let me make changes, even after authenticating. My username wasn't there, and I couldn't add it either. I thought I was screwed...

Anyway, long story short, I found a procedure that let me reclaim control over my hosts file by pushing through what I think is a bug, and the terminal.
  1. In Finder, navigate to /private/etc/
  2. Locate the hosts file
  3. Right-click on it and select Get Info
  4. Unclock the Get Info pane and authenticate
  5. Add yourself as a user (note - after adding, your username still won't appear in the list)
  6. Close the Get Info box
  7. Open Terminal
  8. sudo nano /etc/hosts
  9. CTRL + O to save
  10. Go back to Finder, right-click on the hosts file and Get Info again.
  11. Your username will be there. Set its permissions to Read and Write.

Cheers,

Z
QUOTE Thanks
vansmith

 
vansmith's Avatar
 
Member Since: Oct 19, 2008
Location: Toronto
Posts: 18,352
vansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond repute
Mac Specs: 2012 13" MBP (2.5 i5, 8GB)

vansmith is offline
I'm sure it's more convenient but I'm not sure you want to go around making files outside of the user directory r/w. This is a bad habit to get into (from a security standpoint) and there's a reason that the file has limited permissions.

Perhaps a warning is warranted for such a tip: don't do this for any files unless you absolutely know what you're doing and feel comfortable fixing things (in the case that something goes wrong). Even then, I'd still recommend against doing it.

Important Links: Community Guidelines : Use the reputation system if you've been helped.
M-F Blog :: Write for the blog
Writing a Quality Post
QUOTE Thanks
Shikarnov

 
Shikarnov's Avatar
 
Member Since: Feb 26, 2008
Posts: 542
Shikarnov is a jewel in the roughShikarnov is a jewel in the roughShikarnov is a jewel in the rough

Shikarnov is offline
^ A prudent warning, indeed. Thanks for bringing it up.
QUOTE Thanks
cradom

 
cradom's Avatar
 
Member Since: Feb 14, 2004
Location: Nederland, Texas
Posts: 3,466
cradom has a brilliant futurecradom has a brilliant futurecradom has a brilliant futurecradom has a brilliant futurecradom has a brilliant futurecradom has a brilliant futurecradom has a brilliant futurecradom has a brilliant futurecradom has a brilliant futurecradom has a brilliant futurecradom has a brilliant future
Mac Specs: 13in macbook - 10.10.1

cradom is offline
And of course next time you do a repair permissions it'll probably change back.

Craig Domingue - resident redneck.
“Never argue with an idiot. He will only bring you down to his level and beat you with experience.”, George Carlin
QUOTE Thanks
Raz0rEdge

 
Raz0rEdge's Avatar
 
Member Since: Jul 17, 2009
Location: MA
Posts: 7,737
Raz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant future
Mac Specs: 27" i7 iMac, 24" iMac, 13" Macbook Air, iPhone 5 & 5S, iPod Nano 7th Gen, iPad 2 16GB WiFi, iPad 3

Raz0rEdge is offline
So in the end wouldn't it be easier just to "sudo vi" the file from the terminal preserving the permissions from any disk repairs while keeping your changes.

--
Regards
...Ashwin



Be sure to read the Community Guidelines | The more information you provide, the better answers you get, remember GIGO.
QUOTE Thanks
dekan

 
dekan's Avatar
 
Member Since: Mar 16, 2007
Posts: 756
dekan is a jewel in the roughdekan is a jewel in the rough

dekan is offline
Quote:
Originally Posted by Raz0rEdge View Post
So in the end wouldn't it be easier just to "sudo vi" the file from the terminal preserving the permissions from any disk repairs while keeping your changes.
That's exactly how I do it - except vi is way over my head so I am using nano :-)

QUOTE Thanks
vansmith

 
vansmith's Avatar
 
Member Since: Oct 19, 2008
Location: Toronto
Posts: 18,352
vansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond repute
Mac Specs: 2012 13" MBP (2.5 i5, 8GB)

vansmith is offline
Yes, it would be easier and probably significantly safer.

You could also cobble something together in AppleScript:
Code:
do shell script "open /Applications/TextEdit.app/ /etc/hosts" with administrator privileges
Save that as an application in AppleScript Editor and voila. Each time you launch the application, you can enter your password and then you'll have write access (you might have to unlock the file however).

Important Links: Community Guidelines : Use the reputation system if you've been helped.
M-F Blog :: Write for the blog
Writing a Quality Post
QUOTE Thanks
dekan

 
dekan's Avatar
 
Member Since: Mar 16, 2007
Posts: 756
dekan is a jewel in the roughdekan is a jewel in the rough

dekan is offline
Quote:
Originally Posted by vansmith View Post
Yes, it would be easier and probably significantly safer.

You could also cobble something together in AppleScript:
Code:
do shell script "open /Applications/TextEdit.app/ /etc/hosts" with administrator privileges
Save that as an application in AppleScript Editor and voila. Each time you launch the application, you can enter your password and then you'll have write access (you might have to unlock the file however).
Love it!

QUOTE Thanks
tjahn79

 
Member Since: Feb 06, 2012
Posts: 1
tjahn79 is on a distinguished road

tjahn79 is offline
Quote:
Originally Posted by dekan View Post
That's exactly how I do it - except vi is way over my head so I am using nano :-).
vi is pretty sweet. vim is even better. You can learn vim by typing "vimtutor" into a terminal window. It will walk you through how to navigate and use many of the vi/vim features!
QUOTE Thanks
vansmith

 
vansmith's Avatar
 
Member Since: Oct 19, 2008
Location: Toronto
Posts: 18,352
vansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond repute
Mac Specs: 2012 13" MBP (2.5 i5, 8GB)

vansmith is offline
Quote:
Originally Posted by dekan View Post
That's exactly how I do it - except vi is way over my head so I am using nano :-)
You could use MacVim which is like a "hybrid" in that you can use normal OS X keyboard shortcuts and Vim ones. It provides you with an easy way to transition into the world of Vim.

Important Links: Community Guidelines : Use the reputation system if you've been helped.
M-F Blog :: Write for the blog
Writing a Quality Post
QUOTE Thanks

Post Reply New Thread Subscribe


« mounting smb share through terminal | Safari Can't Find The Server »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
OSX Lion File Sharing to Ubuntu PsykLoki OS X - Operating System 2 09-28-2011 02:52 PM
Can you guys open this site? Desolate One OS X - Apps and Games 13 04-29-2005 02:23 PM
editing hosts file on OSx blackwaterdev Switcher Hangout 2 02-24-2005 09:51 PM
Where is the hosts file? Stoomie OS X - Operating System 3 08-10-2004 04:59 PM

All times are GMT -4. The time now is 11:03 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?