When you deploy a new Linux Virtual Private Server (VPS), you are typically provided with administrative access as the root user. Operating continuously as the root superuser poses substantial security risks: any command is executed without confirmation, and unauthorized attackers frequently target the root username with automated brute-force scripts.
The standard security best practice on Linux is to create a dedicated non-root user with sudo (superuser do) privileges for daily administrative tasks, set up secure SSH key access for that user, and restrict direct root login.
In this step-by-step guide, you will learn how to create a new sudo user, grant administrative rights, configure SSH key authentication, and harden SSH daemon security on Ubuntu 26.04 LTS, Ubuntu 24.04 LTS, Ubuntu 22.04 LTS, and Ubuntu 20.04 LTS on your Aveshost VPS.
Prerequisites
- An active Linux VPS running Ubuntu (26.04, 24.04, 22.04, or 20.04 LTS).
- Root SSH access to your server (see our guide on How to Log in and Access Ubuntu Server via SSH).
- Basic familiarity with SSH keys (see How to Set Up SSH Keys on Ubuntu Server).
Step-by-Step Guide: How to Create a Sudo User on Ubuntu
Step 1: Log in as the Root User
Connect to your Ubuntu server using your terminal:
ssh root@YOUR_SERVER_IP
Step 2: Create a New User Account
Run the adduser command to create a new user (replace sammy with your desired username):
adduser sammy
You will be prompted to:
- Enter and confirm a strong password for the new user account.
- Optionally enter additional contact details (Full Name, Room Number, etc.) or press
ENTERto skip. - Type
Yand pressENTERto confirm the information is correct.
Step 3: Add the User to the Sudo Group
On Ubuntu, members of the sudo group are granted elevated administrative privileges using the sudo command prefix. Add your new user to the sudo group:
usermod -aG sudo sammy
Step 4: Test Sudo Access for the New User
- Switch to your new user account:
su - sammy - Test running a command with
sudo:sudo whoami - Enter your user password when prompted. If the output returns
root, your user has full administrative privileges!
Step 5: Set Up SSH Key Authentication for the New User
To enable passwordless, secure SSH login for your new user account:
- While logged in as your new user (e.g.
sammy), create the.sshdirectory:mkdir -p ~/.ssh chmod 700 ~/.ssh - Create the
authorized_keysfile:nano ~/.ssh/authorized_keys - Paste your local computer’s public SSH key into the file, save, and exit (
CTRL + O,ENTER,CTRL + X). - Secure file permissions:
chmod 600 ~/.ssh/authorized_keys
Step 6: (Security Hardening) Disable Direct Root SSH Login
Now that your sudo user can administer the server and log in via SSH keys, disable direct root SSH logins to prevent unauthorized access:
- Open the SSH daemon configuration file:
sudo nano /etc/ssh/sshd_config - Find the
PermitRootLoginline and change it tono:PermitRootLogin no - (Optional) Disable password authentication as well:
PasswordAuthentication no - Save and exit (
CTRL + O,ENTER,CTRL + X). - Validate SSH configuration syntax and restart the SSH daemon:
sudo sshd -t sudo systemctl restart ssh # On Ubuntu 20.04/22.04: # sudo systemctl restart sshd
ssh sammy@YOUR_SERVER_IP.
Frequently Asked Questions & Troubleshooting
Q: What is the difference between adduser and useradd?
A: adduser is an interactive, friendly Perl wrapper on Ubuntu that creates the home directory and sets passwords automatically. useradd is a low-level system binary that requires multiple manual flags.
Q: How can I remove a user if I no longer need it?
A: Run sudo deluser --remove-home username to delete the user and their home directory.
Q: How do I execute root commands once root SSH login is disabled?
A: Simply prefix administrative commands with sudo (e.g. sudo apt update) or open an interactive root shell when needed using sudo -i.
Need Further Assistance?
If you have questions about configuring sudo user privileges, securing SSH daemon settings, or managing user accounts on your Ubuntu VPS, our technical support team is available 24/7. Feel free to submit a support ticket through your client area for expert assistance.