Sudo to a specific user


You wish to grant user1 sudo access to user2 without prompting for a password.


Edit the /etc/sudoers file by typing the command visudo.

# visudo

Add the following line to the /etc/sudoers file.

user1  ALL=(user2)   NOPASSWD:ALL

Logged in as user1, run the following command to start an interactive bash shell as user2.

# sudo -u user2 bash -i


Note: A common mistake is to use sudo su - user2. This will not work as su is normally run by root (or has the setuid bit set forcing it to run as root) and user1 does not have sudo to root privileges.