Create New sudo Users

Hands-On Lab

 

Photo of Kenny Armstrong

Kenny Armstrong

Linux Training Architect II in Content

Length

01:00:00

Difficulty

Beginner

In a proper production environment, not every user that needs elevated privileges for a server will have the root password. Instead, those users that need to perform system administrative tasks would be granted the ability to use the sudo command when elevated privileges are needed. This learning activity will provide an opportunity to create new users that will be granted varying degrees of sudo access.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Create New sudo Users

Introduction

In this hands-on lab, we'll create new users that will be granted varying degrees of sudo access.

Solution

Open a terminal session, and log in via SSH using the credentials provided on the lab page.

Create Two New Users

  1. Create a gfreeman user on the system:

    sudo useradd -m gfreeman
  2. Create an avance user, and assign it to the wheel supplemental group:

    sudo useradd -G wheel -m avance
  3. Set the password for both accounts to LASudo321:

    sudo passwd gfreeman
    sudo passwd avance

Verify the /etc/sudoers File and Test Access

  1. Verify that the /etc/sudoers file will allow the wheel group access to run all commands with sudo:

    sudo visudo
  2. Note that there should not be a comment (#) on this line of the file:

    %wheel  ALL=(ALL)       ALL
  3. Switch to the avance account, and use the dash (-) to utilize a login shell:

    sudo su - avance
  4. Attempt to read the /etc/shadow file at the console:

    cat /etc/shadow
  5. Rerun the command with the sudo command:

    sudo cat /etc/shadow
  6. After you have verified avance can read the /etc/shadow file, log out of that account:

    exit

Set Up the Web Administrator

  1. Create a new sudoers file in the /etc/sudoers.d directory that will contain a standalone entry for webmasters:

    sudo visudo -f /etc/sudoers.d/web_admin
  2. Enter in the following at the top of the file:

    Cmnd_Alias  WEB = /bin/systemctl restart httpd.service, /bin/systemctl reload httpd.service
  3. Add another line in the file for gfreeman to be able to use the sudo command in conjunction with any commands listed in the WEB alias:

    gfreeman ALL=WEB
  4. Save and close the file.

  5. Next, log in to the gfreeman account:

    sudo su - gfreeman
  6. Attempt to restart the web service:

    sudo systemctl restart httpd.service
  7. Try to read the new web_admin sudoers file:

    sudo cat /etc/sudoers.d/web_admin

    Since the cat command is not listed in the command alias group for WEB, gfreeman cannot use sudo to read this file.

Conclusion

Congratulations on completing this hands-on lab!