How to Add User to Sudoers File on Ubuntu / Debian

Sudo is a program that allows users to run programs with the security privileges of another user (normally the superuser, or root). The /etc/sudoers file controls who can run what commands as what users on what machines and can also control special things such as whether you need a password for particular commands.

To add user to sudoers file, execute this command:

$ sudo visudo

And create new line at the bottom of file:

pikachu   ALL=(ALL)  ALL

Above line will allow user pikachu to run any command on any host as any user.

The structure is HOST=(USER) COMMAND

Another configuration example:

User_Alias     OPERATORS = joe, mike, jude
Runas_Alias    OP = root, operator
Host_Alias     OFNET = 10.1.2.0/255.255.255.0
Cmnd_Alias     PRINTING = /usr/sbin/lpc, /usr/bin/lprm

OPERATORS ALL=ALL
# The users in the OPERATORS group can run any command from any terminal.

linus ALL=(OP) ALL
# The user linus can run any command from any terminal as any user
in the OP group (root or operator).

user2 OFNET=(ALL) ALL
# user user2 may run any command from any machine in the  OFNET network,
as any user.

user3 ALL= PRINTING
# user user3 may run lpc and lprm from any machine.

go2linux ALL=(ALL) ALL
# user go2linux may run any command from any machine acting as any user.

Reference: ubuntu.com, go2linux.org

Leave a Reply

Your email address will not be published. Required fields are marked *