How to Safely Create a New Sudo User on Ubuntu Servers

How to Safely Create a New Sudo User on Ubuntu Servers

I still remember the first time I rented a VPS.

Logged in as root, happy as a kid in a game shop… until I accidentally ran a command that wiped a config file. No backups, no second user, nothing. That was the day I stopped doing everything as root and started creating proper sudo users on every fresh Ubuntu server.

If you’re here, you’re probably in that same boat: you’ve got an Ubuntu server, you’re logging in as root (or as one user), and you want a proper sudo-enabled user without breaking anything.

Let’s fix that cleanly.

Who This Helps (And What We’re Doing)

This guide is for you if:

  • You just got a new Ubuntu server and only have root access
  • You want to create a new user with sudo rights
  • Or you already have a user and just want to give them sudo privileges
  • You’d rather not touch /etc/sudoers and risk locking yourself out

We’re going to:

  1. Log in as root
  2. Create a new user
  3. Add that user to the sudo group
  4. Test sudo access to make sure it works

We’ll stick to the safe, built-in way: using the sudo group, not manually editing /etc/sudoers.

Step 1: Log In to Your Server as Root

First, you need shell access to the server as the root user.

From your local machine, use SSH:

ssh root@your_server_ip_address

Replace your_server_ip_address with your server’s actual IP address.

If your provider gave you a root password, you’ll be prompted for it here. Once you’re in, you’ll see something like:

root@hostname:~#

Being root means you can do anything, including mistakes. So from here on, type carefully.

Step 2: Create a New User (If You Don’t Have One Yet)

If you already have an existing user and just want to give them sudo access, you can skip to Step 3.

To create a new user, run:

adduser sammy

Replace sammy with the username you want.

You’ll be asked for a password:

Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

Pick something strong but memorable. This is the password the user will use both to log in and to authenticate sudo commands.

After that, you’ll see prompts for user details (Full Name, Room Number, etc.). These are optional. You can just press ENTER through them if you don’t care about that info.

At the end you’ll see a confirmation like:

Is the information correct? [Y/n]

Type Y and press ENTER.

At this point, the user exists, but they’re just a normal user. No sudo yet.

Step 3: Add the User to the sudo Group

Ubuntu uses a group called sudo to control who can use administrator privileges.

Anyone in the sudo group can run commands with elevated rights using sudo — and you don’t need to manually edit /etc/sudoers to make that happen. The system already knows: members of sudo get admin powers.

To add your user (for example, sammy) to the sudo group, run this as root:

usermod -aG sudo sammy
  • usermod modifies a user account
  • -aG means: add (-a) this user to these groups (-G sudo)
  • sammy is the username

This is the standard, safe way to grant sudo access on Ubuntu.

No /etc/sudoers editing, no custom files, just group membership.

Step 4: Test the New Sudo User

Now let’s make sure it actually works.

First, switch from root to the new user:

su - sammy

You’ll see the shell prompt change to something like:

sammy@hostname:~$

Now try running a simple command with sudo, for example:

sudo echo "sudo is working"

The first time you use sudo with this user, you should see a password prompt:

[sudo] password for sammy:

Enter the password you set for sammy earlier (not the root password).

If everything is set correctly, you’ll see the output:

sudo is working

That confirms:

  • The user can run sudo
  • Sudo is using their own password for authentication
  • You didn’t need to touch /etc/sudoers

At this point, you can safely start using this user for admin tasks instead of root.

Why sudo Instead of su (And Why This Setup Is Safer)

Quick comparison so you know what you’re actually using:

  • sudo lets a normal user run individual commands with elevated privileges
  • It uses the user’s own password, not the root password
  • Each sudo command can be logged and audited

su, on the other hand:

  • Switches your shell to another user (often root)
  • Requires the target user’s password (for root, that’s the root password)
  • Gives you a full session as that user, not just one command

On a multi-user system, sudo is usually preferred because:

  • You don’t have to share the root password with anyone
  • You can see in the logs which user ran which command
  • Users stay mostly as themselves, only elevating when needed

By adding people to the sudo group, you’re using Ubuntu’s built-in, expected way of granting admin rights with those benefits.

Safety Notes and Common Gotchas

A few quick safety tips and things to watch out for.

  1. Don’t edit /etc/sudoers unless you really have to
    For normal use, Ubuntu already handles sudo access via the sudo group. Manually editing /etc/sudoers can easily lock you out if you make a typo.

  2. Use strong passwords
    The user’s password controls both login and sudo access. Weak password = weak server.

  3. Test sudo before logging out root
    Always verify sudo works with the new user before you close your root session. If something is wrong, you can still fix it as root.

  4. Know that sudo is powerful
    Members of the sudo group effectively have full administrative privileges. Only add users you trust.

  5. Use non-interactive shells for special system users
    If you ever create service-type users (not for humans), you can use shells like /usr/sbin/nologin or /bin/false to prevent them from logging in interactively. That improves security for those system accounts.

Recap and Next Step

Quick recap of what you did:

  • Logged in as root with SSH:
    bash
    ssh root@your_server_ip_address
  • Created a new user (if needed):
    bash
    adduser sammy
  • Added that user to the sudo group:
    bash
    usermod -aG sudo sammy
  • Switched to the user and tested sudo:
    bash
    su - sammy
    sudo echo "sudo is working"

That’s it. You now have a proper sudo-enabled user on your Ubuntu server, using the built-in group method instead of risky manual config edits.

If this worked for you, keep CrushEdge handy for the next fix.

No Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.