How To Create a Sudo User on Ubuntu 20.04 LTS

How do I create a new user with sudo access on Ubuntu 20.04 LTS Linux server? Can you tell me command to add sudo user on Ubuntu 20.04 Linux server?

The sudo command allows us to run any or selected command as another user as specified by the security policy by the system administrator. This page explains how to create a sudo user on Ubuntu 20.04 LTS server.

ADVERTISEMENTS

Procedure to create a sudo user on Ubuntu 20.04 LTS

Let us see all steps to create a new user account named wendy and give it sudo access to run all commands. In other words, the wendy user is going to be a sysadmin.

Step 1 – Log in to the server using ssh.

Use the ssh command to log in as root user:
ssh root@your-cloud-server-ip-here
ssh root@server1.cyberciti.biz

Step 2 – Create a new user account on Ubuntu.

Next use the adduser command add a user named wendy, enter:
adduser user-name-here
adduser wendy

Add Sudo User on Ubuntu 20.04 LTS
Please note that you need to provide the new user password as other information as prompted on the screen. When done entering all information, make sure you type “Y” to “Is the information correct?” prompt. You can press [ENTER] key for the default except for the password prompt.

Step 3 – Add the new user to the sudo group.

Now we have added a user named wendy with a password. It is time to add the wendy user account to the sudo group. All members of the sudo group granted sudo and root-level access on Ubuntu and Debian based systems. Therefore to add the wendy user you just created to the sudo group, run any one of the following command:
adduser wendy sudo
OR
usermod -aG sudo wendy

Sample outputs:

Adding user `wendy' to group `sudo' ...
Adding user wendy to group sudo
Done.

Step 4 – Test sudo user account.

Now user wendy can login using the ssh command command as follows from their own desktop:
ssh wendy@server1.cyberciti.biz
ssh wendy@server-ip-here

The first time you use the sudo command, you will be promoted for the password of the wendy user account. Hence, type the wendys password to gain root access. Any command type with sudo should run with root privileges for the wendy account. To gain root shell, enter:
sudo -s
Verify that wendy can use the sudo command:
sudo ls -l /root/
test ssh sudo session

Step 5 – How to run a command using sudo

The syntax is:
sudo [option] command
sudo -i
sudo -s
sudo systemctl restart nginx.service
sudo tail -f /var/log/rsnapshot.log

The -i option run the shell specified by the target user’s password database entry as a login shell. This means that login-specific resource files such as .profile, .bash_profile or .login will be read by the shell. The -s executes the shell specified by the SHELL environment variable if it is set or the shell specified by the invoking user’s password database entry. If a command is specified, it is passed to the shell for execution via the shell’s -c option.

Ubuntu 20.04 add sudo user (existing users)

We can configure sudo for an existing user account too. In other words, add an existing user named vivek to sudo using the following syntax. First, make sure user account named vivek exist using the grep command and /etc/passwd file:
grep '^username-here' /etc/passwd
grep '^vivek' /etc/passwd

Now add that user to the sudo group:
adduser {exiting-user-name} sudo
adduser vivek sudo

Verify using the id command:
id vivek
How To Create a Sudo User on Ubuntu 20.04 Linux LTS system

A note about removing sudo access

Simply run the following deluser command:
deluser USERNAME sudo
deluser wendy sudo
id wendy

Sample outputs:

Removing user `wendy' from group `sudo' ...
Done.

Conclusion

You learned how to add a user account with access and privileges to run system administrator’s commands on Ubuntu 20.04 LTS systems. See sudo command man page here for more info.

This entry is 6 of 6 in the Linux and Unix sudo Tutorial series. Keep reading the rest of the series:
  1. Linux Login as Superuser ( root user )
  2. How can I log in as root?
  3. Ubuntu create a new sudo user on Ubuntu Linux server
  4. Add a new user account with admin access on Linux
  5. CentOS 8 Linux create a Sudo User
  6. Ubuntu 20.04 LTS create a sudo user
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.