Duplicate, Edit Locked Hosts File on Mac OS X 10.7 Lion

By Sidharth | Apple

Hosts file is like an address book where you’re given the control to block a handful of websites, restrict advertisement from appearing on webpages, and exclude objectionable content found on the Internet.

Editing and duplicating the entries of hosts file on Mac OS X 10.7 Lion and Snow Leopard machine is as easy as editing on Windows platform.

However, with the stable Mac OS X Lion, Apple just got a little smarter in restricting access to hosts file.

Duplicate Hosts File

Even though if you are the admin of your Mac, you are not able to save the original hosts file located at /etc/hosts.

Unlock Hosts File?

Whether you are using an iMac, MacBook Air, or MacBook Pro, there’s no easy solution to unlock the locked hosts file. If you duplicate hosts file, you’ll probably end up with another version of hosts file, which acts no more than just a backup of the original hosts file.

Some of the errors encountered while dabbling with the hosts file are as follows:

The file hosts cannot be unlocked. You can duplicate this document and edit the duplicate.

You don’t own the file hosts and don’t have permission to write to it. You can duplicate this document and edit the duplicate. Only the duplicate will include your changes.

Terminal comes to the rescue if you want to manually edit the hosts file, even if the file is locked.

Steps to edit locked hosts file on Mac OS X Lion:

  1. Go to Spotlight and launch Terminal by typing in the keyword Terminal. You can also find Terminal under Applications -> Utilities -> Terminal.
  2. Now type this command in the Terminal screen: sudo nano /etc/hosts
  3. Terminal will prompt for your Mac’s admin password. Enter the password and you’ll be able to edit the hosts file.
  4. Once you’ve done editing the hosts file, hit the CTRL+X keys and then press Y (yes) to confirm and save the changes.

About the Author

Hi, I am Sidharth. Full-time blogger. Editor of Blogote. And a self-proclaimed geek!

Leave a Comment:

(8) comments

Germanmexican March 8, 2015

on Yosemite 10.10.2 the above was working in terms of getting the host files to show up in terminal but it would not actually edit them when checking int he folder. What worked for me was sudo nano /private/etc/hosts bu tthen pressing ctrl O and then enter.

thanks though, this got me on the right track . let’s hope iPhone updates now.

MisterKnister December 26, 2012

Thanks it worked but my problem is still there 🙁

Jorn Voegtli October 5, 2012

When i type sudo nano /etc/hosts in terminal it comes up with
Voegtlis-MacBook-Pro-2:~ voegtliheidi$ sudo nano/etc/hosts
sudo: /private/etc/sudoers is mode 0644, should be 0440
sudo: no valid sudoers sources found, quitting
Voegtlis-MacBook-Pro-2:~ voegtliheidi$
what am i doing wrong?

    Jorn Voegtli October 5, 2012

    nevermind it worked

Max August 10, 2012

Hi. It is easy way to edit hosts file is using terminal. Open terminal
sudo nano /private/etc/hosts

Edit and save. Done.

Mikkel August 9, 2012

Cheers buddy it worked, recommended your post. 🙂

Frank October 20, 2011

Hi mate,

I tried this (with sudo, pico, iv, gasmask, textwrangler, textmate, restoring disk permissions, verifying disk permissions, everything!) and it still says I don’t have permission to edit the file. Any ideas what i’m doing wrong?



Add Your Reply

Leave a Comment: