How to add a sudo enabled user on Rocky Linux 8 ? Print

  • add user, rocky linux, rocky linux 8, sudo user
  • 0

The sudo command provides a mechanism to grant administrator privileges to all other users on the server. These admin privileges are usually available only to the root user. This guide will help 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 user, please go 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 — Add a New User

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

  1. adduser user123

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

 

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

  1. passwd user123

 

Output
Changing password for user user123.
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 user123
 

 

Step 4 — Test 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 - user123
 

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 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 user123:

 

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.


Was this answer helpful?

« Back