Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon

Create New sudo Users

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.

Google Cloud Platform icon

Path Info

Clock icon Beginner
Clock icon 1h 0m
Clock icon Nov 12, 2018

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    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
    1. Set the password for both accounts to LASudo321:
       sudo passwd gfreeman
       sudo passwd avance
  2. Challenge

    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
    1. 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
    1. As the avance user, attempt to read the /etc/shadow file at the console:
        cat /etc/shadow
    1. As a regular user, avance does not have sufficient privileges to do so. Rerun the command with the sudo command:
        sudo cat /etc/shadow
    1. After you have verified that avance can read the /etc/shadow file, log out of that account:
  3. Challenge

    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
    1. 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
    1. 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
    1. Save and close the file.

    2. Next, log into the gfreeman account:

        sudo su - gfreeman
    1. Attempt to restart the web service:
        sudo systemctl restart httpd.service
    1. 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.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

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.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans