Enable superuser when logged in with another user

privilegesrootsudousers

Suppose that the machine has two users:

  • Alice (admin)
  • Bob (standard user)

While Bob is logged in, how can Alice modify a root file (Bob does not have this permission even with sudo)?

Alice tried:

$ sudo vim /etc/hosts
[sudo] password for Bob: 
Bob is not in the sudoers file.  This incident will be reported.

Best Answer

Use su:

su - alice
sudo vim /etc/hosts

From man su:

   The su command is used to become another user during a login session.
   Invoked without a username, su defaults to becoming the superuser. The
   optional argument - may be used to provide an environment similar to
   what the user would expect had the user logged in directly.

For more information, see

man su

and Wikipedia.

Related Question