SSH is the main way to manage a Linux VPS, so it should be secured before the server is used for public services. Start by adding an SSH key and a sudo user, then reduce password-based access where possible.

Do not lock down SSH until you have tested a second login method. Keep one working SSH session open while making changes.

  1. Add an SSH key: How to add an SSH key to your VPS.
  2. Create a sudo user: How to create a sudo user on a Linux VPS.
  3. Test that the sudo user can log in with the SSH key.
  4. Edit the SSH config:
sudo nano /etc/ssh/sshd_config

Common hardening options are:

PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes

Linux VPS terminal showing SSH hardening options and active SSH service status

 

What these options change

OptionEffect
PermitRootLogin noStops direct root logins. Admins log in as a normal user and use sudo.
PasswordAuthentication noStops password SSH logins. Users must use SSH keys.
PubkeyAuthentication yesAllows SSH key authentication.

 

Restart SSH

On Ubuntu or Debian, the service is usually named ssh:

sudo systemctl restart ssh

On AlmaLinux, Rocky Linux, Oracle Linux, and most CentOS-style systems, the service is usually named sshd:

sudo systemctl restart sshd

 

Test before closing the old session

  1. Leave the current SSH session open.
  2. Open a second terminal.
  3. Connect with the new user and key.
  4. Run sudo whoami.
  5. Only close the old session after the new one works.

If you lock yourself out, use the VPS console to repair /etc/ssh/sshd_config.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to connect to a Linux VPS with SSH

SSH is the normal way to manage a Linux VPS. It gives you a terminal on the server so you can...

How to update packages on a Linux VPS

Keeping packages updated helps patch security issues and keeps server tools compatible. Run...

How to create a sudo user on a Linux VPS

A sudo user lets you manage a Linux VPS without logging in as root for every task. This is safer...

How to check disk usage on a Linux VPS

Disk usage issues can stop updates, backups, logs, databases, and game saves from writing...

How to check CPU and RAM usage on a Linux VPS

High CPU or RAM usage can cause lag, slow command responses, failed updates, or game servers...