Kurbis

Tech blog

Enable sudo

February 09, 2014

This post explains how to configure sudo under Slackware.

First, make sure you have sudo installed, given that it is not part of the base installation.

$ slackpkg install sudo

Afterwards, it is necessary to edit the file "/etc/sudoers" and enable one of the sudo mechanisms. Below, I have listed all of the possible mechanisms. They are pretty much self-explanatory.

## Uncomment to allow members of group wheel to execute any command
# %wheel ALL=(ALL) ALL 

## Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL 

## Uncomment to allow members of group sudo to execute any command
# %sudo ALL=(ALL) ALL 

## Uncomment to allow any user to run sudo if they know the password
## of the user they are running the command as (root by default).
# Defaults targetpw  # Ask for the password of the target user
# ALL ALL=(ALL) ALL  # WARNING: only use this together with 'Defaults targetpw' 

## Read drop-in files from /etc/sudoers.d
## (the '#' here does not indicate a comment)
#includedir /etc/sudoers.d

From the sudo mechanisms above, uncomment whichever works best for you. In my opinion, the following sudo mechanism seems to provide a good compromise between usability and security, and after uncommenting it look as follows.

## Uncomment to allow members of group wheel to execute any command
%wheel ALL=(ALL) ALL

At this point, the next configuration steps depend on which sudo mechanism you have enabled in the previous step. If you have enable the sudo mechanism for the wheel group, then you need to add the users you want to give sudo power to the group wheel, if they are not already part of this group. If you enabled the sudo mechanism for the sudo group, then you have to add those users to the sudo group.

In any case, in order to add a user to a group, simply run the following command, where "" is the login name of the user you want to give sudo power.

$ gpasswd -a <user> wheel

It might be the case that the user you are giving sudo power is in fact yourself, or that the users you are giving sudo power are already logged in. Given that the group definitions are only updated when you login, all group updates will require those users to logout and login again.

For example, if user "john" was not part of the group "wheel", and you added "john" to this group, and he was already logged in, then "john" will have to logout and login again in order for the changes to the groups to take effect.

Sources: Adding users to sudoers file

Tags: slackware