How To Create a Sudo User on Ubuntu

By 

Updated on

5 min read

Create a Sudo User on Ubuntu

When setting up a fresh Ubuntu server, one of the first things you want to do is create a regular user account with administrative rights. This lets you run privileged commands with sudo instead of logging in as root, which is safer and leaves a clearer audit trail.

This guide shows you how to create a new user on Ubuntu, give it a home directory, and grant it sudo access.

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:

Terminal
ssh root@server_ip_address

If you already have a non-root account with sudo access, log in with that account and prefix the commands below with sudo.

2. Create a new user account

Create a new user account with the adduser command. Do not forget to replace username with the user name that you want to create:

Terminal
adduser username

You will be prompted to set and confirm the new user password. Use a strong password for the new account.

output
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

Once you set the password, the command creates a home directory at /home/username, copies the default configuration files from /etc/skel into it, and prompts you for the new user’s information. Press ENTER to accept the defaults if you want to leave these fields blank.

output
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]

The home directory is created automatically, so you do not need to pass any extra flag. This is one of the main reasons adduser is the recommended tool on Ubuntu.

3. Add the new user to the sudo group

On Ubuntu, any user that belongs to the sudo group is granted sudo access. Add the user to the sudo group with the usermod command:

Terminal
usermod -aG sudo username

The -a flag appends the user to the group without removing it from other groups, and -G specifies the supplementary group to add.

You can also add an existing user to the sudo group with adduser:

Terminal
adduser username sudo

This is an alternative to usermod -aG sudo username. Use it only after the account already exists.

adduser vs useradd

Ubuntu ships with two commands for creating users, and the difference matters when you care about the home directory:

  • adduser is an interactive Perl script that creates the user, creates the home directory at /home/username, copies the files from /etc/skel, and prompts for the password. This is the recommended command on Ubuntu and Debian.

  • useradd is the low-level user-management command. By default it does not create a home directory. To create the home directory, pass the -m flag:

    Terminal
    useradd -m -s /bin/bash username
    passwd username
    usermod -aG sudo username

For interactive use on Ubuntu, prefer adduser. Reach for useradd in automation scripts where you want deterministic, non-interactive behavior.

Test the sudo access

Switch to the newly created user:

Terminal
su - username

Use sudo to run the whoami command:

Terminal
sudo whoami

If the user has sudo access, the output of the whoami command will be root:

output
root

How to use sudo

To use sudo, prefix the command with sudo and a space:

Terminal
sudo ls -l /root

The first time you use sudo in a session, you will be prompted for the user password:

output
[sudo] password for username:

If you want certain users or commands to run without a password prompt, see how to run sudo without a password .

Troubleshooting

username is not in the sudoers file. This incident will be reported.
The user is not a member of the sudo group. Log in as root (or another sudo user) and run usermod -aG sudo username, then log out and back in so the group membership is applied to the new session.

sudo: command not found
The sudo package is not installed on the system, which is common on minimal server images and containers. Install it as root with apt update && apt install sudo.

Group membership not taking effect
Group changes are applied on login. If sudo still fails after adding the user to the sudo group, log out of the user session and log back in, or start a new shell with su - username.

FAQ

How do I create a sudo user with a home directory on Ubuntu?
Run adduser username as root. The adduser command creates the home directory at /home/username by default and copies the skeleton configuration from /etc/skel. Then add the user to the sudo group with usermod -aG sudo username.

What is the difference between adduser and useradd?
adduser is an interactive wrapper that creates the home directory, sets the password, and configures the account in one step. useradd is the low-level command and does not create a home directory unless you pass the -m flag. On Ubuntu, use adduser for interactive work and useradd for scripts.

How do I remove sudo access from a user?
Remove the user from the sudo group with deluser username sudo (or gpasswd -d username sudo). The account itself remains active and can still log in; it just loses sudo privileges.

Can I grant sudo access without adding the user to the sudo group?
Yes. Create a drop-in file under /etc/sudoers.d/ that defines a rule for that specific user or command. This is also the recommended way to restrict a user to a limited set of commands.

Conclusion

You now have a regular user account with sudo privileges on Ubuntu. Use it for daily administration, and keep the root account reserved for recovery or break-glass access. For advanced sudo rules, such as allowing specific commands without a password, see the sudoers configuration guide .

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page