sudo

Use vim to edit sudo:

EDITOR=vim visudo

On Ubuntu, set the default editor:

sudo update-alternatives --config editor

Display sudo commands the user can run:

sudo -l

Run a command as a specific user:

sudo -u beandog -- whoami

Switch to another user:

sudo -u beandog -s

Syntax

<user/group> <hostnames>= [(<users>)] [NOPASSWD: [ALL|/usr/bin/command,/usr/bin/command2]]

Examples

Let user alan run rdiff-backup as another user, not requiring a password:

alan ALL= (clientuser) NOPASSWD: /usr/bin/rdiff-backup

Let user alan run one command as root:

alan ALL= NOPASSWD: /usr/sbin/backup-manager

Allow user steve to run any command as user beandog without asking for password:

steve ALL=(beandog) NOPASSWD: ALL

Set PATH for new user. sudo will not pass the user's PATH when switching to another user by default, which can cause problems if calling binaries in /usr/local. Override it with the secure_path option.

Defaults secure_path = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin