Editing a file you don’t have permissions to
Sometimes you’ll want to edit a file that your user doesn’t have write permissions for. For example if you’re a regular user and you want to edit /etc/hosts
– a file owned by root, and writable only by root – you’ll need to either become root or use the sudo
command. See the Users and Groups chapter for more.
In this case, you’d use sudo
to execute your editing command as root:
sudo $EDITOR /etc/hosts
sudo nano /etc/hosts
sudo vi /etc/hosts