On the mac, the user you use to log in is by default not the super user (root) account. This is a security feature (Least Privilege) that is by design.
Along with that security model, sudo
is a tool that is provided to allow regular (non-root) users to perform root tasks on a case by case basis.
This prevents a whole host of issues, not the least of which is royally screwing up your machine by accident. :)
The /etc/sudoers
file is designed to be able to be distributed among multiple servers. In order to accomplish this, each permission in the file has a host portion.
This is usually set to ALL=
which means that the permission is valid for any server, however it can be set to specific hosts:
%sudo kaagini=(ALL) ALL
In order for sudo to know wether this rule should be applied, it needs to lookup the host it is running on. It uses a call that relies on the /etc/hosts
being correct, which is why it fails if it is not right.
It might be argued that sudo
doesn't need to bother doing a name lookup if the host portion is set to ALL=
for all permissions, but it just doesn't work that way - it appears to work out where it running is prior to processing the rules.
This is really for ease of maintenance as sudo only reads /etc/sudoers to see what the user can do on the current machine. But as an admin with 100 servers, this might require 100 different /etc/sudoers files to maintain. Because sudoers has a host portion in the permissions, you can maintain a single sudoers file and distribute it to all machines, yet still have granularity over what users can do on each machine.
Best Answer
From the bash manual:
And from the
sudo
man page:So,
sudo !!
means to execute the previous command as the superuser.