The sudo command provides a mechanism for granting administrator privileges to normal users.
Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Sudo queries on Linux System.
In this context, we shall look into the method to create a sudo user on Ubuntu.
Also, you can use this user account to execute administrative commands without a need to logging in to your Ubuntu server as a root user.
How to Create a sudo user on Ubuntu ?
With the below steps, you can create a new user and give sudo access to it. You can skip user creation steps if you wants to give sudo access to existing user.
i. Begin by logging into your Ubuntu server as root user:
$ ssh root@server ip address
ii. Once logged in, Create a new user account using adduser command. Replace 'linuxapt' with your desired user name:
$ adduser linuxapt
You will be prompted to set new password and retype the new user password. It's recommended to set a strong password with combination of alphanumeric and special characters.
You will see an output such as this:
Adding user `linuxapt' ...
Adding new group `linuxapt' (1001) ...
Adding new user `linuxapt' (1001) with group `linuxapt' ...
Creating home directory `/home/linuxapt' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Once you set password it will make a directory for a new user and make copy necessary configuration files. After that it will prompt to enter new user's information. These are optional questions so If you want to leave all of this information blank just press ENTER to accept the defaults. It will look like this:
Changing the user information for linuxapt
Enter the new value, or press ENTER for the default
Full Name :
Room Number :
Work Phone :
Home Phone :
Is the information correct? [Y/n]
By default on Ubuntu machine, members of the sudo group are granted with sudo access. Now, user is created and we will add new user to sudo group to grant sudo access.
$ usermod -aG sudo linuxapt
How to Test sudo access ?
Login using new created user or you can switch to the new created user by type :
$ su - linuxapt
Use the sudo command to run the whoami command:
$ sudo whoami
If new user account have sudo access then output of given command will be root as below :
Now you can use sudo by just type sudo before any command and give space :
$ sudo ls -la /root
First time it will prompt you to enter user password for that session :
[sudo] password for linuxapt:
[Need urgent assistance in fixing Sudo related errors on Ubuntu Linux System ? We can help you. ]