This article demonstrates how to set up and use a new user with sudo privilege and delete user on ubuntu 20.04
The
command provides a privilege to execute or run programs with the security privileges of another user (by default, as the root user). When we use sudo it will prompt for the password and confirms your request to execute a command by checking a file, called sudo
sudoers
.
1. Create a new user
First, we have to log in to our server as the root user.
sudo -i
Then execute the
command to add a new user to the system.adduser
For example, if we need to add a user “guide” to our system, we have to run
adduser guide
Please replace the user name “guide” with the user that you want to create.
- This will ask for a new password for this account.
New password: Retype new password: passwd: password updated successfully
- Then we have to provide user information. It is not mandatory to provide values, We can leave all blank if we want.
Changing the user information for guide 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
2. Give sudo privilege to the user
Now we have to add the created user to the user group. Ubuntu group members have privileges. For that, we have to use the usermod
command.
usermod -aG sudo guide
Now to verify the created user we will switch to the user and try to execute sudo
commands. We can use the su
command to switch between user accounts.
YOUR_SERVER# su - guide To run a command as administrator (user "root"), use "sudo <command>". See "man sudo_root" for details. guide@YOUR_SERVER:~$
Run
It is usually used to extend your sudo password timeout but can be used for determining whether you have any sudo -v
sudo
privileges.
- It will ask for your password the first time to proceed.
guide@YOUR_SERVER:~$ sudo -v [sudo] password for guide:
After you give the correct password command will run with the privilege of the
group.sudo
3. Delete existing user
In this section we are going to delete the existing user there are several ways to delete ubuntu user. Here we talk about
- Delete user without deleting any of user’s files
sudo deluser guide
Please replace the user name “guide” with the user that you want to delete.
- Delete user with user’s home directory
sudo deluser --remove-home guide
Please replace the user name “guide” with the user that you want to delete.
Pingback: Install Ansible on Ubuntu 20.04 - Onload Code