How to Create a New Sudo User on Ubuntu

In Linux and other Unix-like systems, the root account has the highest access rights on the system. It is used specifically for system administration purposes.

The root user (sometimes referred to as the superuser) has all rights or permissions (to all files and programs) in all modes (single or multi-user).

Operating a Linux system especially a server using the root account is considered insecure for several reasons. These include among others the risk of damage from accidents (e.g running a command that erases the filesystem), and running system applications with elevated privileges opening the system to security vulnerabilities. Besides the root account is a target for every attacker.

Read Also: Difference Between su and sudo and How to Configure sudo in Linux

With respect to the above security concerns, it is recommended to use the sudo command to gain root privileges when a system user really needs to. On Ubuntu, the root account is disabled by default and the default account is an administrative account which uses sudo to gain root privileges.

In this short article, we will explain how to create a sudo user on Ubuntu Linux distribution.

Creating a New Sudo User in Ubuntu

1. Log in to your Ubuntu server as the root user.

$ ssh root@server_ip_address

2. Next, create a new sudo user using the useradd command as shown, where an admin is a username. In the following command, the -m flag means to create the user’s home directory if it doesn’t exist, -s specifies the user’s login shell and -c defines a comment to be stored in the account file.

$ sudo useradd -m -s /bin/bash -c "Administrative User" admin

3. Create a password for the admin user using the passwd utility and confirm the new user’s password. A strong password is highly recommended!

$ sudo passwd admin
Create New Sudo User in Ubuntu
Create New Sudo User in Ubuntu

4. To enable the user admin to invoke sudo to perform administrative tasks, you need to add the user to the sudo system group using the usermod command as follows, where the -a option means to append user to a supplementary group and -G specifies the group.

$ sudo usermod -aG sudo admin

5. Now test sudo access on a new user account by switching to admin’s account (enter admin’s account password when prompted).

$ su - admin
Switch to Sudo Account
Switch to Sudo Account

6. Once switched to admin user, verify that you can run any administrative task, for example, try to create a directory tree under the / directory by adding sudo to the command.

$ mkdir -p /srv/apps/sysmon
$ sudo mkdir -p /srv/apps/sysmon
Run Administrative Commands Using Sudo
Run Administrative Commands Using Sudo

The following are other guides about sudo that you will find useful:

  1. 10 Useful Sudoers Configurations for Setting ‘sudo’ in Linux
  2. How to Show Asterisks While Typing Sudo Password in Linux
  3. How to Keep ‘sudo’ Password Timeout Session Longer in Linux

That’s all for now. In this guide, we have shown how to create a sudo user on Ubuntu. For more details about sudo, see “man sudo_root“. Do you have any questions or thoughts to share? If yes, reach us via the feedback form below.

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.