Table of Contents
The sudo command is designed to allow users to run programs with the security privileges of another user, by default the root user.
In this post, 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.
Create a Sudo User in Ubuntu Linux Server
1. Log in to your system as the root user:
ssh root@server_ip_address
2. Create a new user account using the adduser command. Don’t forget to replace username with the user name that you want to create:
adduser username
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.
root@ub20:~# adduser bon
Adding user `bon' ...
Adding new group `bon' (1001) ...
Adding new user `bon' (1001) with group `bon' ...
Creating home directory `/home/bon' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for bon
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] y
4. 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 username
Test the sudo access
Switch to the newly created user:
su - username
To use sudo, simply prefix the command with sudo and space:
sudo ls -l /root
The first time you use sudo in a session, you will be prompted to enter the user password:
[sudo] password for username:
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.