sudo
is a Linux command which provides a mechanism for allowing administrator privileges to a normal user. In this tutorial, you are going to learn how to create sudo user on Ubuntu.
In this guide, we will show you how to create a new user on an Ubuntu machine and give it sudo
access. 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.
Creating a New Sudo User in Ubuntu
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:
ssh root@server_ip_address
2. Create a new user account
Create a new user account using the adduser command
adduser rasho
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.
Example output:
Adding user `rasho' ... Adding new group `rasho' (1001) ... Adding new user `rasho' (1001) with group `rasho' ... Creating home directory `/home/username' ... Copying files from `/etc/skel' ... New password: Retype new password: passwd: password updated successfully
[ads]
Once you set the password the command will create a home directory for the user, copy 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.
Changing the user information for rasho Enter the new value, or press ENTER for the default Full Name []: Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n]
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:
usermod -aG sudo rasho
Test the sudo access
Now, test sudo access on a new user account by switching to rasho’s account.
su - rasho
Use the sudo command to run the whoami
command:
sudo whoami
If you have sudo access then you will get below output:
root
How to use sudo
To use sudo, simply prefix the command with sudo and space:
sudo ls -la /root
Now enter the password of the new user to get the list of files:
#Output [sudo] password for username:
Conclusion
That’s all for now. In this guide, we have shown how to create a sudo user on Ubuntu. For more details about sudo, see “man sudo_root“. Do you have any questions or thoughts to share? If yes, reach us via the feedback form below.