When you deploy a new Linux Virtual Private Server (VPS), administrative control is initially provided through the superuser root account. However, operating continuously as root presents serious security risks: accidental commands cannot be undone, and automated brute-force scripts continuously target the root username across the Internet.
The standard security best practice across all Linux distributions is to create a dedicated non-root user with sudo (superuser do) privileges for daily system administration, configure SSH key access for that user, and restrict direct root logins.
In this guide, we will walk you through creating a sudo user and hardening SSH security across Ubuntu, Debian, AlmaLinux, Rocky Linux, RHEL, and CentOS on your Aveshost VPS.
Prerequisites
- An active Linux VPS running Ubuntu, Debian, AlmaLinux, Rocky Linux, or CentOS.
- Root SSH access (see How to Log in and Access Linux VPS via SSH).
- Basic familiarity with SSH keys (see How to Set Up SSH Keys on Linux VPS).
Step 1: Create a New User on Your Linux Distribution
Option A: Ubuntu & Debian
# Add user interactively (replace 'sammy' with your username)
adduser sammy
Enter and confirm a strong password, then press ENTER through the optional contact prompts.
Option B: AlmaLinux, Rocky Linux, RHEL & CentOS
# Create user and home directory
useradd -m -s /bin/bash sammy
# Set user password
passwd sammy
Step 2: Grant Sudo / Administrative Privileges
Administrative groups differ depending on the Linux distribution family:
- On Ubuntu & Debian: Add user to the
sudogroup:usermod -aG sudo sammy - On AlmaLinux, Rocky Linux & RHEL: Add user to the
wheelgroup:usermod -aG wheel sammy
Step 3: Test Sudo Privileges
- Switch to the new user account:
su - sammy - Execute a command using
sudo:sudo whoami - Enter your user password. If the output returns
root, administrative privileges are active!
Step 4: Configure SSH Key Authentication for the Sudo User
While logged in as your new user (e.g. sammy), set up SSH key authentication:
mkdir -p ~/.ssh
chmod 700 ~/.ssh
nano ~/.ssh/authorized_keys
Paste your local computer’s public SSH key into the file, save, and exit (CTRL + O, ENTER, CTRL + X), then set permissions:
chmod 600 ~/.ssh/authorized_keys
# If on AlmaLinux/Rocky Linux with SELinux:
restorecon -Rv ~/.ssh
Step 5: Disable Direct Root SSH Login (Security Hardening)
- Open the SSH daemon configuration file:
sudo nano /etc/ssh/sshd_config - Find
PermitRootLoginand change it tono:PermitRootLogin no - Save and exit (
CTRL + O,ENTER,CTRL + X). - Test syntax and restart SSH:
sudo sshd -t # On Ubuntu/Debian: sudo systemctl restart ssh # On AlmaLinux/Rocky Linux/RHEL: sudo systemctl restart sshd
ssh sammy@YOUR_SERVER_IP.Frequently Asked Questions & Troubleshooting
Q: Why does AlmaLinux/Rocky Linux use the "wheel" group instead of "sudo"?
A: The wheel group is the traditional Unix convention for administrative users maintained across all Red Hat Enterprise Linux derivatives.
Q: How do I delete a user when no longer needed?
A: Run sudo userdel -r username to remove the user and their home directory.
Need Further Assistance?
If you have questions about configuring user privileges or securing SSH settings on your Linux VPS, our technical support team is available 24/7. Feel free to submit a support ticket for expert assistance.