New

EmeraldHost 2.0 is here: faster, more intuitive, and made for everyone - the new panel!

Learn more
Guides
Basic ConfigurationSecure SSH Access

How to Secure SSH Access on Your Linux VPS

Secure SSH access on a Linux VPS with SSH keys, disable root login and change SSH port

3 min read
Mar 16, 2026

This guide shows you how to protect your VPS from attackers by setting up SSH keys, disabling root login and changing the SSH port.

1. Create SSH key

First, create an SSH key pair on your local PC.

Windows (PowerShell)

ssh-keygen -t ed25519

Linux / macOS (Terminal)

ssh-keygen -t ed25519

Confirm the default path with Enter and optionally set a passphrase for additional protection.

Two files are created:

  • ~/.ssh/id_ed25519 – your private key (never share this!)
  • ~/.ssh/id_ed25519.pub – your public key (this goes on the server)

2. Upload public key to the server

Upload from Linux / macOS

ssh-copy-id root@YOUR_SERVER_IP

Upload from Windows (PowerShell)

type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh root@YOUR_SERVER_IP "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

3. Create a new user (optional)

Optionally, you can create a separate user instead of logging in as root.

adduser myuser

Grant the user sudo rights:

usermod -aG sudo myuser

Copy the SSH key to the new user:

mkdir -p /home/myuser/.ssh
cp ~/.ssh/authorized_keys /home/myuser/.ssh/authorized_keys
chown -R myuser:myuser /home/myuser/.ssh
chmod 700 /home/myuser/.ssh
chmod 600 /home/myuser/.ssh/authorized_keys

4. Disable root login and password authentication

Open the SSH configuration:

sudo nano /etc/ssh/sshd_config

Find and change the following line:

PasswordAuthentication no

If you created a separate user in step 3, you can also disable root login:

PermitRootLogin no

Save with Ctrl + O, close with Ctrl + X and restart the SSH service:

sudo systemctl restart sshd

5. Change SSH port

By default SSH runs on port 22. Changing this reduces automated brute-force attacks.

Open the SSH configuration:

sudo nano /etc/ssh/sshd_config

Find the line #Port 22 and change it to:

Port 2222

If you are using UFW, allow the new port before restarting:

sudo ufw allow 2222/tcp

Restart the SSH service:

sudo systemctl restart sshd

From now on, connect with:

ssh -p 2222 root@YOUR_SERVER_IP

Summary

Measure Effect
SSH key Secure authentication without passwords
New user No direct root access
Disable root login Blocks root login attempts
Disable password auth Prevents brute-force attacks
Change SSH port Reduces automated attacks
Written byEmeraldHost Team
Last updated on Mar 16, 2026 Edit on GitHub

Did this article help you?

Your feedback helps us improve our guides.

Help shape the guides

€10.00 in credit for every new guide, €5.00 for every improvement.

Contact Support

Create a support ticket and our team will get back to you as soon as possible – personal and professional.

Go to Support
1257 members online

Discord Community

Connect with other players, get quick help from the community, and stay up to date with the latest news.

Join Discord

Join our Discord community 1257 members online right now