Create New sudo Users

1 hour
  • 3 Learning Objectives

About this Hands-on Lab

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.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create two new users.
  1. Create two new users on the system, and assign the avance user to the wheel supplemental group:
    sudo useradd -m gfreeman
    sudo useradd -G wheel -m avance
  2. Set the password for both accounts to LASudo321:
    sudo passwd gfreeman
    sudo passwd avance
Verify the `/etc/sudoers` file and test access.
  1. Using the visudo command, verify that the /etc/sudoers file will allow the wheel group access to run all commands with sudo. There should not be a comment (#) on this line of the file:
    %wheel  ALL=(ALL)       ALL
  2. From the cloud_user login, use the su (substitute user) command to switch to the avance account, and use the dash (-) to utilize a login shell:
    sudo su - avance
  3. As the avance user, attempt to read the /etc/shadow file at the console:
    cat /etc/shadow
  4. As a regular user, avance does not have sufficient privileges to do so. Rerun the command with the sudo command:
    sudo cat /etc/shadow
  5. After you have verified that avance can read the /etc/shadow file, log out of that account:
Set up the web administrator.

Now we need to configure gfreeman‘s account to have the ability to restart or reload the web server when needed. Since he will be the webmaster, he needs sudo permissions to restart the service.

  1. First, create a new sudoers file in the /etc/sudoers.d directory that will contain a standalone entry for webmasters. Use the -f option with the visudo command to create this new file:

    sudo visudo -f /etc/sudoers.d/web_admin
  2. Enter in the following at the top of the file. This will create an alias command group that we can apply to any user or group that we add to this file. This group of commands will contain the necessary commands for restarting or reloading the web server:

    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 into the gfreeman account:

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

    sudo systemctl restart httpd.service
  7. Now gfreeman can restart the web server. As the gfreeman user, try to read the new web_admin sudoers file with the sudo command:

    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.

Additional Resources

You are working at an organization that has just hired two new technicians. One of them will be the backup system administrator, while the other will need the ability to perform some tasks on the system with elevated privileges. You will create these two new accounts, and through the modification of the /etc/sudoers file and a separate sudoers file, these two new users will be able to invoke the sudo command.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?