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


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.
  • Jorn Voegtli

    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

      nevermind it worked

  • http://www.gezitatilrehberi.net/ Max

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

    Edit and save. Done.

  • Mikkel

    Cheers buddy it worked, recommended your post. :-)

  • Frank

    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?

    Thanks,

    Frank

Top