The sudo command on the ubuntu system is useful to get sudo privileges on the machine to perform administrative tasks. It allows running user programs with the security privileges of the root user.
In this article, we will discuss how to create a sudo user on Ubuntu machines. This type of sudo accounts can be used to execute administrative commands without login to the Ubuntu server as the root user.
Table of Contents
Steps to create a sudo user
Follow the simple steps mentioned below and create a new user account on Ubuntu. Additionally, you will have to provide sudo access as well. If you have an existing user and want to configure sudo for an existing user, then skip to step 3.
1. Login to your Ubuntu server
ssh [email protected]_ip_address
In the above command, server_ip_address is the ipv4 address of your server. For example, If the IP address is 127.0.0.1 then write like this.
2. Create a new user account
To create a new user account on Ubuntu Linux, you will have to use adduser command. Enter the following command on the terminal.
In the above command, replace linuxtor with the desired username you want to use.
After writing the command, hit the Enter button. You will be prompted to enter and reconfirm the new password for linuxtor account. Make sure to enter a strong password for your account.
[Output] Adding user `linuxtor' ... Adding new group `linuxtor' (1001) ... Adding new user `linuxtor' (1001) with group `linuxtor' ... Creating home directory `/home/linuxtor' ... Copying files from `/etc/skel' ... New password: Retype new password: passwd: password updated successfully
After setting up the password for linuxtor user account. The command will automatically create a home directory for linuxtor user. It will also add some configuration files in the ubuntu home directory. It will ask you to set such configurations. If you want to leave the default settings, just press ENTER to proceed ahead with default values.
[Output] Changing the user information for linuxtor 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 new user to the sudo group
To provide administrative access to any user on ubuntu systems. you will have to grant access to the user by adding to the sudo group. To add a new user to sudo group you will have to use the usermod command indicated as below.
usermod -aG sudo linuxtor
In above command, linuxtor is a username, replace it with your username.
Now, we’re done! Let’s check whether our configurations are correct or not. To do that, we will switch to the newly created user using su command.
su - linuxtor
It will ask for the password of linuxtor user. Type the password and press ENTER.
[Output] [sudo] password for linuxtor:
Now, enter whoami command with sudo to know the status of the current user you are logged in.
If the given user have sudo access, then it will return output as below.
How to use sudo command
To use sudo command, type sudo before any command you enter in Linux terminal.
sudo ls -a
More on how to create a sudo user on ubuntu
I am pretty confident that you have learned how to create a user with sudo permissions. Next, log in to your Ubuntu server with your created user account (In my case I will use linuxtor username) using sudo command. There are many more sudoers tweaks for ubuntu that you should know. We will discuss that in the next guide. Stay tuned.