How To Create a Sudo User on CentOS

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Introduction

The sudo command provides a mechanism for granting administrator privileges, ordinarily only available to the root user, to normal users.

There is a SuperUser named root. The root user can do anything and everything, and thus doing daily work as the root can be very dangerous. You could type a command incorrectly and destroy the system. The sudo command allows a permitted user to run a command as the superuser (root user) or another user, as specified by the security policy. Often the sudo used on servers to give admin permissions and privileges to ordinary users.

This guide will show you the easiest way to create a new user with sudo access on CentOS without having to modify your server’s sudoers file.

Note: If you want to configure sudo for an existing user, kindly skip to step number 4.

Create a New Sudo User on CentOS

1. Log in to your server as the root user.

ssh root@ip_address_of_server

2. Use useradd command to add a new user.

useradd username

Note: replace username with the user that you want to create.

3. Use the passwd command to create a new password to user you have been created.

passwd username

Set the new user’s password . A strong password highly recommended.

Example:

4. Use the usermod command to add the user to the wheel group.

usermod -aG wheel username

Note: On CentOS, members of the wheel group have sudo privileges.

5. Test sudo privileges on new user account

  • Use the su command to switch to the new user account.
su - username

Verify that you can use sudo by running sudo to the command that you want to run with superuser privileges.

sudo command_to_run

Example:

sudo ls /

Note: The first time you use sudo in a session, The password will be required for the new user . Enter the password to proceed as shown above in the screenshot.

Conclusion

In this tutorial we illustrated you how to create sudo user on CentOS, we created a new user account and added it to the sudo group to enable sudo access.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
MQ-Jr
MQ-Jr
unixcop Admin

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook