How to create a new sudo user on Ubuntu Linux server

I am a new Ubuntu Linux 16.04.xx LTS server user. How do I create a new sudo user on my server? How do I add a new user as sudoer file using the command line option on Ubuntu?

In Linux (and Unix in general), there is a SuperUser named root. The root user can do anything and everything, and thus doing daily work as the root can be very dangerous. You could type a command incorrectly and destroy the system. The sudo command allows a permitted user to run a command as the superuser (root user) or another user, as specified by the security policy. Often the sudo used on servers to give admin permissions and privileges to ordinary users. In this quick tutorial, you will learn how to create a sudo user on Ubuntu.

Steps to create a new sudo user on Ubuntu

  1. First add the user, run: sudo adduser <UserNameHere>
  2. Add the user to sudo group by typing the command in terminal for Ubuntu version 12.04 and above: sudo adduser <UserNameHere> sudo
  3. In older version of Ubuntu (version 12.04 and older), run: sudo adduser <UserNameHere> admin
  4. Verify it: id <UserNameHere>

More about admin and sudo group on Ubuntu server

The members of the admin group may gain root privileges. All members of group sudo run any command on Ubuntu server. So just add the user to the sudo group on Ubuntu server. The admin group has been deprecated since Ubuntu version 12.04 and above. Hence, no longer exists or used in Ubuntu 12.04 or above. The reason it works:
# grep -B1 -i '^%sudo' /etc/sudoers
$ sudo grep -B1 -i '^%sudo' /etc/sudoers
Sample outputs:

# Allow members of group sudo to execute any command

Let us see some practical examples.

How to add a new user named vivek to sudo using the command line?

Open the terminal or login to your remote server:
$ ssh root@server-name-IP-here
$ ssh
{ root@server:/root} #

How to add the user named vivek

# adduser vivek
$ sudo adduser vivek
Sample outputs:

Fig.01: How to add the new user on Ubuntu

How to create a sudo user on Ubuntu for vivek account

Type the following command:
# adduser vivek sudo
OR use the usermod command to add user to group on Linux:
# usermod -aG sudo vivek
$ sudo usermod -aG sudo vivek
$ sudo adduser vivek sudo
Sample outputs:

Fig.02: Add user vivek to sudo to get administrator privileges

How to print user account info

Verify new user and group membership with the [nicmd name=”id”]:
$ id vivek
Sample outputs:

Fig.03: Show user and group information

How to test sudo access for vivek user account

Now user vivek can login using the ssh command command as follows:
$ ssh
Verify that vivek can use sudo command:
$ sudo cat /etc/sudoers
The first time you use sudo command, you will be asked for the password of the vivek account. So type the vivek’s password to gain root access. Any command type with sudo should run with root privileges for vivek account. To gain root shell, enter:
$ sudo -s
Sample outputs:

Fig.03: Testing sudo access for vivek user account

And there you have it. Allowing other users to run sudo on Ubuntu server and granting users administrator privileges.

This entry is 3 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

🐧 Please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 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 VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
1 comment… add one
  • Md. Abdullah Al Mamun Jan 22, 2017 @ 6:25

    Excellent tips

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @