How To Create A Sudo User On Ubuntu.
In this guide, we will show you how to create a new user with sudo access on Ubuntu systems. You can then use this user account to execute administrative commands without a need to logging in to your Ubuntu server as a root user.
Steps to Create a Sudo User
Follow the steps below to create a new user account and give it sudo access. If you want to configure sudo for an existing user, skip to step 3.
1. Log in to your server.
Log in to your system as the root user:
2. Create a new user account.
Create a new user account using the adduser command. Don’t forget to replace username with the user name that you want to create:
You will be prompted to set and confirm the new user password. Make sure that the password for the new account is as strong as possible.
Once you set the password the command will create a home directory for the user, several configuration files in the home directory, and prompts you to set the new user’s information. If you want to leave all of this information blank just press ENTER to accept the defaults.
3. Add the new user to the sudo group
By default on Ubuntu systems, members of the group sudo are granted with sudo access. To add the user you created to the sudo group use the usermod command:
Test the sudo access
Switch to the newly created user:
Use sudo to run the whoami command:
Is the user have sudo access then the output of the whoami command will be “root”:
How to use sudo
To use sudo, simply prefix the command with sudo and space:
The first time you use sudo in a session, you will be prompted to enter the user password:
You have learned how to create a user with sudo privileges. You can now log in to your Ubuntu server with this user account and use sudo to run administrative commands.