JRehkemper.de

Grant sudo-privileges to users

If you want to grant sudo-privileges to a user, there are two ways.

Add to Group

The simple one is to add the user to the corresponding group. This is easy but doesn’t allow you to limit the sudo-privileges in any way.

The group for sudo is called differently depending on your distribution.
Debian and Ubuntu based distributions use the sudo-group.
RHEL based systems use the wheel-group.

# Debian
[tux@server]$ usermod -aG sudo username

# RHEL
[tux@server]$ usermod -aG wheel username

Add to sudoers-file

The more granular way is to specify the user in a configuration file in /etc/sudoers.d/*. That way you can limit sudo to certain commands, if you want to.
You can call the configuration-file whatever you want, but I like to call mine like the username.

/etc/sudoers.d/username

# Grant all privileges
username ALL=(ALL)

# Grant all privileges without asking for password again
username ALL=(ALL) NOPASSWD:ALL

# Grant only privileges for ls-command
username ALL=(ALL) /usr/bin/ls

# Grant only privileges for ls-command and do not ask for password
username ALL=(ALL) /usr/bin/ls NOPASSWD:/usr/bin/ls
profile picture of the author

Jannik Rehkemper

I'm an professional Linux Administrator and Hobby Programmer. My training as an IT-Professional started in 2019 and ended in 2022. Since 2023 I'm working as an Linux Administrator.