Sudo: Great Power, Great Responsibility

This post should really be called How to modify the /etc/hosts file on a Mac but how do you resist an opportunity to hail Sudo?

While installing a Hadoop distribution on my sandbox, one of the requisite steps for configuring the network was to edit the /etc/hosts file to include the IP address, fully qualified domain name, and short name of the hosts in the cluster.

From the terminal, I logged on to the remote server via ssh and ran the following commands:

cat /etc/hosts

vi /etc/hosts

The result of the first displayed the contents of the file, and the second gave a warning about changing a read-only file, and did not quite take the edits I was trying to make. Not until I used sudo:

sudo vi /etc/hosts

This got me over, and I completed the necessary edits. Additional tip for Mac users: hit esc before entering the save and exit command, to exit the editor. On that note:

:wq