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


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 sudo group:
    usermod -aG sudo sammy
  • On AlmaLinux, Rocky Linux & RHEL: Add user to the wheel group:
    usermod -aG wheel sammy

Step 3: Test Sudo Privileges

  1. Switch to the new user account:
    su - sammy
  2. Execute a command using sudo:
    sudo whoami
  3. 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)

  1. Open the SSH daemon configuration file:
    sudo nano /etc/ssh/sshd_config
  2. Find PermitRootLogin and change it to no:
    PermitRootLogin no
  3. Save and exit (CTRL + O, ENTER, CTRL + X).
  4. Test syntax and restart SSH:
    sudo sshd -t
    # On Ubuntu/Debian:
    sudo systemctl restart ssh
    # On AlmaLinux/Rocky Linux/RHEL:
    sudo systemctl restart sshd
CRITICAL VERIFICATION: Before closing your current session, open a new terminal tab and verify that you can connect with your sudo user: 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.

Je li Vam ovaj odgovor pomogao? 0 Korisnici koji smatraju članak korisnim (0 Glasovi)