How to Create a Sudo User on Ubuntu 24.04 and Disable Root Login Print

  • 0

Running everything as root is the single most common mistake on new Ubuntu servers. The root account has unlimited power — there is no confirmation, no undo, and no audit trail. The professional approach on Ubuntu 24.04 is a personal user with sudo privileges: you work as a normal user and elevate only when needed, with every elevated command logged in /var/log/auth.log.

Step 1 — Create the new user

Logged in as root (or another sudo user), run:

adduser sarah

Ubuntu's adduser is friendlier than the low-level useradd: it creates the home directory, copies default dotfiles and prompts for a password interactively. Pick a strong password — better yet, plan to switch to SSH key authentication and disable passwords entirely.

Creating a new user with adduser and adding it to the sudo group on Ubuntu

Step 2 — Add the user to the sudo group

On Ubuntu, membership of the sudo group is what grants administrative rights:

usermod -aG sudo sarah

The -aG flags mean append to the group — do not forget the -a, or you will replace the user's existing groups instead of adding one.

Step 3 — Verify sudo access

su - sarah
sudo whoami

If the output is root, your new account can administer the server.

Verifying sudo privileges with sudo whoami on Ubuntu 24.04

Step 4 — Disable direct root login

Once the sudo user works (test it in a second SSH session before closing your current one), lock root out of SSH. Edit /etc/ssh/sshd_config:

PermitRootLogin no

Then restart SSH:

sudo systemctl restart ssh
Warning: Always confirm the new user can log in over SSH and run sudo before disabling root login. Locking yourself out of a remote VPS usually means a trip to your provider's rescue console.

Useful sudo tricks

Run a whole root shell when you have many commands: sudo -i. Repeat the last command with sudo after a “permission denied”: sudo !!. See what a user may run: sudo -l -U sarah. Remove sudo rights again with gpasswd -d sarah sudo.

Frequently asked questions

Why not just use root with a strong password?

Because every attacker on earth knows the username is root — half of the brute-force problem is already solved for them. A named sudo user plus Fail2Ban and key-only SSH reduces that attack surface to effectively zero.

What is the difference between sudo and su?

su switches to the root account and requires the root password. sudo runs a single command with elevation using your own password, is logged per-command, and can be granted or revoked per user.

Related Ubuntu guides

Prefer to have experts handle it?

LFA IT provides fully managed Ubuntu VPS and dedicated servers — initial setup, security hardening, monitoring and 24/7 support, so you can focus on your business. Explore our hosting and server management services or open a support ticket and our engineers will take it from there.


Was this answer helpful?

« Back