Search The Hostwinds Guides Knowledge Base

Create a sudo user (CentOS 7)

Share This Article [TheChamp-Sharing]

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 absolute easiest way to create a new sudo user in CentOS 7 that has sudo access. If you’d just like to create a normal user that does not have sudo access, checkout 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 that has 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 new accounts privileges by switching to the new account


su - newusernamehere



Step 5:  The new user should have sudo permissions which should allow 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



The first time that 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. Having and 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.


Related Articles