02-01-2012, 01:09 PM #1Tip: Unlocking Hosts file in Lion
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.
- In Finder, navigate to /private/etc/
- Locate the hosts file
- Right-click on it and select Get Info
- Unclock the Get Info pane and authenticate
- Add yourself as a user (note - after adding, your username still won't appear in the list)
- Close the Get Info box
- Open Terminal
- sudo nano /etc/hosts
- CTRL + O to save
- Go back to Finder, right-click on the hosts file and Get Info again.
- Your username will be there. Set its permissions to Read and Write.
02-01-2012, 01:40 PM #2
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.
02-01-2012, 01:52 PM #3
02-01-2012, 03:19 PM #4
And of course next time you do a repair permissions it'll probably change back.Delusions are often functional. A motherís opinions about her childrenís beauty, intelligence, goodness, et cetera ad nauseam, keep her from drowning them at birth.
02-01-2012, 04:36 PM #5
- Member Since
- Jul 17, 2009
- 27" i7 iMac, 24" iMac, 13" Macbook Air, iPhone 6S, iPod Nano 7th GeniPad 3
02-01-2012, 04:57 PM #6
02-01-2012, 05:03 PM #7
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
02-01-2012, 06:33 PM #8
02-06-2012, 01:04 PM #9
- Member Since
- Feb 06, 2012
02-06-2012, 01:19 PM #10
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.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
By ankhseeker in forum OS X - Operating SystemReplies: 10Last Post: 12-18-2014, 11:54 AM
By Shikarnov in forum OS X - Operating SystemReplies: 4Last Post: 04-01-2013, 01:27 PM
By afcbob in forum OS X - Operating SystemReplies: 2Last Post: 11-29-2009, 12:21 PM
By traveler09 in forum OS X - Operating SystemReplies: 3Last Post: 07-29-2009, 07:59 AM
By Stoomie in forum OS X - Operating SystemReplies: 3Last Post: 08-10-2004, 03:59 PM