Sudo as Another User

A sudo in Linux allows to execute commands with the security privileges of another user, by default the root user.

This short note shows how to run commands as another user using sudo.

Sudo as Another User

To run a command as root:

$ sudo <command>

To run a command with the security privileges of another user:

$ sudo -u <username> <command>

To run a command as another user with the environment of another user:

$ sudo -i -u <username> <command>

To switch to another user’s shell:

$ sudo -i -u <username>

Leave a Reply