Hostwinds Tutorials

Search results for:

Table of Contents

How To Create A User With Sudo Access In CentOS 7

Create a sudo user (CentOS 7)

Tags: CentOS Web Panel 

How To Create A User With Sudo Access In CentOS 7

In some cases, when you execute commands on your server or computer, they need to be executed with root privileges. However, you may not have access to the root account itself, or you may have that type of access limited on your server for security reasons. This is where the "sudo" command comes in to save the day! By using the sudo command, you can temporarily grant or escalate root-level privileges to a normal user. This article will teach you the easiest way to create a new sudo user in CentOS 7 with sudo access. Suppose you'd like to create a normal user that does not have sudo access. Check out our article: How To Create A New User (CentOS 7). Please be aware that you'll need to access your server using SSH. If you're not certain how to access your server via SSH, please refer to the following guide: Connecting To Your Server Via SSH.

How To Create A User With Sudo Access In CentOS 7

To create a new user with sudo access, you'll need to have access to the root account. However, this is only for the initial creation process. Once you have access to the server using the root account, please move on to the following procedure.

Step 1: Issue the adduser command to add a new user to your server

adduser newusernamehere

Step 2: Change the password for the new user

passwd newusernamehere

Step 3: Add the new user to the wheel group using the usermod command

usermod -aG wheel newusernamehere

Step 4: At this point, you can test the privileges of the new account by switching to the new account

su - newusernamehere

Step 5: The new user should have sudo permissions, allowing you to execute any command with the word sudo prefixed before the command. For example, you can list the contents of the root directory like so

sudo ls -alh /root

When you use sudo in a session, you'll be prompted for the password to complete the command. If you followed this guide and the password was entered correctly, you should now see the directory listing for the root user. Using a sudo user is an excellent security practice, as it ensures that you can still enjoy the benefits of having the root user's privileges without some of the risks associated with using the root account all of the time.

Written by Michael Brower  /  March 8, 2017