How to Create a Sudo User on Ubuntu

How to Create a Sudo User on Ubuntu

ยท

2 min read

It's already Friday, and I'm delighted ๐Ÿ˜‰ to see you here.

Another day of problem-solving, so we'll see how it goes.

The sudo command allows regular users to gain administrator rights that are usually only available to the root user. This post will show you how to create a new sudo user on Ubuntu 18.04 or 20.04.2.0 without having to change the /etc/sudoers file on your server.

follow the steps below to achieve the expected result

1. Login / ssh into your server

ssh root@your-server

OR

Use this command if you are already logged in to the server to switch to the root user.

sudo -i

2. Create New User

Use the adduser command to add a new user to your system:

#adduser soft

You may add sudo if you are not logged in with the root user account.

You will be prompted to enter a new password and retype the new password.

Adding user `soft' ...
Adding new group `soft' (1002) ...
Adding new user `soft' (1002) with group `soft' ...
Creating home directory `/home/soft' ...
Copying files from `/etc/skel' ...
New password:

After that, you'll be prompted to enter some details about the new user. Accepting the defaults and leaving all of this information blank is fine, but you can also set them.

Enter the new value, or press ENTER for the default
    Full Name []: Idris
    Room Number []: 1234
    Work Phone []: 01-279019
    Home Phone []: 44-795004
    Other []: 
Is the information correct? [Y/n]

3. Add user to sudo group

To add the user to the sudo group, execute the usermod command, replacing soft with the username you just added. All members of the sudo group have full sudo rights by default on Ubuntu.

usermod -aG sudo soft

4. Switch to the new account and Test sudo access

sudo soft

Check that you can use sudo as a new user by appending sudo to the command you want to run with superuser privileges.

Now run any command to test, for example.

sudo ls -a

When you use sudo for the first time in a session, you'll be requested for that user's password. To continue, enter the password:

Yay ๐Ÿฅณ we were able to create a new user on our machine.

I'd love to connect with you at Twitter | LinkedIn | GitHub

See you next Friday in DevOpsFriday series. Take care!!!

ย