Configuring sudo Access for Users

Learn about configuring sudo access for users.

About Configuring sudo Access

Learn about configuring sudo access.

The sudo command enables trusted users to have administrative access to systems without having to log in using root user passwords.

When users have sudo access, they can precede an administrative command with sudo, and then be prompted to enter their password. After authentication is complete, and assuming that the command is permitted, the command is processed as if it had been run by the root user.

Configuring sudo Access for Users

Learn about configuring sudo access for users.

You need root privileges to configure sudo access for users.

  1. Log in to the system as the root user.

  2. Create a new user account using the useradd command with the -G support option. This ensures the new user is added to the support group, granting them SSH access to the appliance.

    For example, to create a normal user account for the user psmith:

    # useradd -G support psmith
  3. Set a password for the user using the passwd command.

    For example:

    # passwd psmith
    Changing password for user psmith.
    New password: <new_password>
    Retype new password: <new_password>
    passwd: all authentication tokens updated successfully
  4. Run the visudo utility to edit the /etc/sudoers file.

    # visudo

    The sudoers file defines the policies that the sudo command applies.

  5. Find the lines in the sudoers file that grant access to users in the wheel group when enabled.

    ## Allows people in group wheel to run all commands
    # %wheel        ALL=(ALL)       ALL
  6. Remove the comment character (#) at the start of the second line, which begins with %wheel.

    This enables the configuration option.

  7. Save your changes and exit the editor.

  8. Add the user account that you created earlier to the wheel group using the usermod command.

    For example:

    usermod -aG wheel psmith
  9. Test that the updated configuration enables the user that you created to run commands using sudo.

    1. Use the su command to switch to the new user account that you created.

      # su psmith
    2. Use the groups command to verify that the user is in the wheel group.

      $ groups
      psmith wheel
    3. Use the sudo command to run the whoami command.

      Because this is the first time that you have run a command using sudo from this user account, the banner message is displayed. You will be prompted to enter the password for the user account.

      $ sudo whoami

      The following output should appear:

      We trust you have received the usual lecture from the local System
      Administrator. It usually boils down to these three things:
      #1) Respect the privacy of others.
      
      #2) Think before you type.
      
      #3) With great power comes great responsibility.

      Enter the password when prompted:

      [sudo] password for psmith: <password>
      root

      The last line of the output is the user name that is returned by the whoami command. If sudo access has been configured correctly, then this value is root.