Blog · WebJi® India

Add a Sudo User in Ubuntu

Quick answer: A sudo user on Ubuntu is a normal account in the sudo group. Create it with adduser priya, grant rights with usermod -aG sudo priya, then log in as that user in a second session and run sudo whoami; root means it works.
✓ In business since 2005✓ INR + GST billing✓ 24/7 Email Support — avg reply < 60 min
Indian freelancer's desk with a laptop showing a website, potted plant and coffee in warm window light — how to add sudo user in ubuntu

What a sudo user is on Ubuntu

A sudo user on Ubuntu is an ordinary account that may run a single command as root by putting sudo in front of it, because the account belongs to the sudo group. The account keeps its own password, home folder and shell, and root keeps no shared login.

  • Root is the superuser account. It can do anything and asks for no permission check.
  • sudo runs one command as root, asks for the user's own password, and logs the action.
  • The sudo group is the switch: /etc/sudoers already grants its members full sudo rights.

The sequence below creates the account, adds the group, and proves the login works before you close the session you are already using. That order is what keeps you out of a lockout on a remote server.

Create the account with adduser

Work from a session that already has root or sudo rights. If you are on the machine's console as root, skip the first step.

  1. Connect as the existing admin: ssh root@your-server-ip, or ssh in as your own sudo user.
  2. Create the account: adduser priya, replacing priya with the name you want.
  3. Type the new password twice. adduser shows nothing as you type, which is normal.
  4. Press Enter through Full Name, Room Number, Work Phone and Home Phone. They are optional.
  5. Answer Y to the confirmation, then check the account exists with id priya.

You know it worked when id priya prints a uid, a gid and a group list, and ls /home shows a folder for the new account. A message that the user already exists means the name is taken; pick another one.

Give the account sudo with usermod -aG sudo

One command adds the group. The two flags matter more than the command itself.

  1. Run usermod -aG sudo priya.
  2. Read the flags: -G sets supplementary groups and -a appends to them instead of replacing them.
  3. Confirm with groups priya. The output should end with sudo.

You know it worked when groups priya lists sudo. Leaving out -a is the classic mistake: usermod -G sudo priya strips every other supplementary group the account had, which on some servers removes access to Docker or a shared data folder.

adduser priya sudo does the same job and is easier to remember, because on Ubuntu adduser also adds an existing user to a named group.

Test the login before you close your session

Group membership is read when a session starts, so the old session cannot prove the change. Open a second one and test there.

  1. In a new terminal, log in as the new account: ssh priya@your-server-ip.
  2. Run sudo whoami and enter priya's password when asked.
  3. Read the answer. root means sudo works for this account.
  4. Optionally list the rights: sudo -l -U priya shows what the account may run.

You know it worked when the command returns root, not priya. Only then close the original root session. If the test fails, the original session is still open, which is exactly why the test comes before the disconnect.

Add a limited sudo rule in /etc/sudoers.d

Full root is not always the right grant. A drop-in file can allow named commands only, which suits a deploy account that restarts a service but never touches user accounts.

  1. As an admin, run sudo visudo -f /etc/sudoers.d/priya.
  2. Add one line: priya ALL=(root) /usr/bin/systemctl restart nginx.
  3. Save and exit. In nano that is Ctrl and O, Enter, then Ctrl and X.
  4. Test as priya: sudo systemctl restart nginx succeeds, and sudo cat /etc/shadow is refused.

You know it worked when the allowed command runs and an unrelated one is rejected with a sudoers message. Always edit through visudo: it checks syntax before saving, and a broken sudoers file can lock every admin out of sudo at once.

Fix the sudoers and group errors

Three messages cover almost every failed attempt. Each one has a single cause.

MessageCause and fix
priya is not in the sudoers file. This incident will be reported.The session started before the group change. Log out and back in, then check groups.
usermod: group 'sudo' does not existA minimal install without the sudo package. As root run apt update then apt install sudo, then repeat usermod.
The account lost its other groupsusermod -G ran without -a. Add the missing groups back with usermod -aG docker priya.
sudo asks for a password and rejects itThe account has no password set, or it was typed wrong twice. As an admin run passwd priya to reset it.

Root account: when to enable it, and how to switch it off

Ubuntu ships with the root account locked, which is why a fresh install cannot log in as root. If you need it for console recovery, set a password deliberately.

  1. As a sudo user run sudo passwd root and set a strong password.
  2. Switch to it with su -, which asks for the root password, not yours.
  3. Leave it enabled only if console access depends on it. Otherwise lock it again with sudo passwd -l root.

SSH is a separate switch. PermitRootLogin no in /etc/ssh/sshd_config, followed by systemctl restart ssh, stops root logins over the network while leaving the console route open. Keep a tested sudo session open while you restart SSH. The root password guide covers the reset path when the old one is lost.

When to email support

Email support@webji.services when a VPS console refuses the new login, SSH stops accepting connections after a config change, or the sudo group is missing and you have no root session left to install it. Include the Ubuntu version, the exact command and the message it returned.

Email support is 24/7 in Hindi and English, and the average first reply is under 60 minutes. The office phone is not a support line. On VPS hosting you get root over SSH plus a console, so a broken sudoers file is recoverable without a rebuild; larger configurations are quoted by email before payment.

Frequently Asked Questions

How do I add a sudo user in Ubuntu?

Log in as root or as an existing sudo user, run adduser priya to create the account, then run usermod -aG sudo priya. Log in as priya in a second session and run sudo whoami. A reply of root means the account has sudo access.

What is the difference between adduser and useradd?

adduser is the interactive wrapper: it asks for a password, creates the home folder and copies the default files. useradd is the low-level tool that creates the account only, so you set the password and home folder yourself. On Ubuntu, adduser is the shorter route.

Why does sudo say the user is not in the sudoers file?

The session started before the group change. Log that user out and back in, then run groups to confirm sudo is listed. If it is still missing, the usermod command did not complete.

Do I have to log out after adding a user to the sudo group?

Yes. Group membership is read when the session starts, so the new rights appear after a fresh login. Keep your current root or sudo session open until the new login has been tested.

How do I remove sudo access from a user?

Run sudo deluser priya sudo, or sudo gpasswd -d priya sudo, then confirm with groups priya. Remove any file you created for that user in /etc/sudoers.d as well.

Can I enable the root account in Ubuntu?

Yes. Run sudo passwd root to give root a password, then su - switches to it. That only affects local or console login; SSH still refuses root unless PermitRootLogin is changed in sshd_config.

Need help with this?

WebJi® support does it for you — free. Talk to our Jaipur team →