How to create a sudo user on Ubuntu

s2 0

the sudo The command was designed to allow users to run programs with another user’s security rights, the root user by default.

In this guide, we are going to show you how to create a new user with sudo access on Ubuntu systems. With this user account, you can then run administrative commands without having to log into your Ubuntu server as the root user.

Steps to create a sudo user

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 [email protected]_ip_address

2. Create a new user account.

Create a new user account with the adduser Command. Don’t forget to replace username with the username you want to create:

adduser username

You will be asked to set and confirm the new user password. Make sure the password for the new account is as strong as possible.

Adding user `username' ...
Adding new group `username' (1001) ...
Adding new user `username' (1001) with group `username' ...
Creating home directory `/home/username' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully

After you set the password, the command creates a home directory for the user, copies several configuration files to the home directory, and prompts you for the new user’s information. If you’d like to leave all of this information blank, just press ENTER to apply the default settings.

Changing the user information for username
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, they are members of the group on Ubuntu systems 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

Use sudo
let them run whoami Command:

sudo whoami

If the user has sudo access, the output of the whoami The command is “root”:

root

How to use sudo

To use sudo, just make the command. Ahead sudo and place:

sudo ls -l /root

When using for the first time sudo In a session you will be asked to enter the user password:

[sudo] password for username:

Conclusion

You learned how to create a user with sudo permissions. You can now log into your Ubuntu server with this user account and use it sudo to execute administrative commands.

That’s all! Feel free to leave a comment if you have any questions.