Tutorial

How To Create a New Sudo-enabled User on Rocky Linux 8 [Quickstart]

Published on February 6, 2023

Senior DevOps Technical Writer

How To Create a New Sudo-enabled User on Rocky Linux 8 [Quickstart]
Not using Rocky Linux 8?Choose a different version or distribution.
Rocky Linux 8

Introduction

The sudo command provides a mechanism for granting administrator privileges — ordinarily only available to the root user — to normal users. This guide will show you how to create a new user with sudo access on Rocky Linux 8, without having to modify your server’s /etc/sudoers file.

Note: If you want to configure sudo for an existing Rocky Linux user, skip to step 3.

Step 1 — Logging Into Your Server

SSH in to your server as the root user:

  1. ssh root@your_server_ip_address

Use your server’s IP address or hostname in place of your_server_ip_address above.

Step 2 — Adding a New User to the System

Use the adduser command to add a new user to your system:

  1. adduser sammy

Be sure to replace sammy with the username you’d like to create.

Use the passwd command to update the new user’s password:

  1. passwd sammy

Remember to replace sammy with the user that you just created. You will be prompted twice for a new password:

Output
Changing password for user sammy. New password: Retype new password: passwd: all authentication tokens updated successfully.

Step 3 — Adding the User to the wheel Group

Use the usermod command to add the user to the wheel group:

  1. usermod -aG wheel sammy

Once again, be sure to replace sammy with the username you’d like to give sudo privileges to. By default, on Rocky Linux, all members of the wheel group have full sudo access.

Step 4 — Testing sudo Access

To test that the new sudo permissions are working, first use the su command to switch from the root user to the new user account:

  1. su - sammy

As the new user, verify that you can use sudo by prepending sudo to the command that you want to run with superuser privileges:

  1. sudo command_to_run

For example, you can list the contents of the /root directory, which is normally only accessible to the root user:

  1. sudo ls -la /root

The first time you use sudo in a session, you will be prompted for the password of that user’s account. Enter the password to proceed:

Output
[sudo] password for sammy:

Note: This is not asking for the root password! Enter the password of the sudo-enabled user, not the root password.

If your user is in the proper group and you entered the password correctly, the command that you used with sudo will run with root privileges.

Conclusion

In this quickstart tutorial you created a new user account and added it to the wheel group to enable sudo access. For more detailed information on setting up a Rocky Linux 8 server, please read our Initial Server Setup with Rocky Linux 8 tutorial.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors
Default avatar

Senior DevOps Technical Writer

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
1 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

How do you create and set the user’s group?

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.