HomeBlog › SSH Key VPS

SSH Key Authentication on VPS:
Complete Setup Guide 2026

📅 September 1, 2026 ⏱ 12 min read 🏷 VPS · Security

SSH Key Authentication on VPS Linux Server Security

📋 Table of Contents

  1. What is SSH Key Authentication?
  2. Why Use SSH Keys Instead of Passwords?
  3. How SSH Key Authentication Works
  4. Generating an SSH Key Pair
  5. Uploading Your Public Key to the Server
  6. Configuring sshd_config for Security
  7. Disabling Password Authentication
  8. Setup Guide for Windows Users
  9. Managing Multiple SSH Keys
  10. Troubleshooting Common Issues
  11. Frequently Asked Questions
  12. Summary

Using a password to log into your VPS is increasingly risky. Bots around the world continuously scan for servers listening on Port 22 and attempt Brute Force attacks 24/7. The most effective solution is switching to SSH Key Authentication — without a password to guess, Brute Force attacks become completely futile.

1. What is SSH Key Authentication?

SSH Key Authentication is an authentication method that uses a cryptographic key pair consisting of:

When connecting, the server sends a challenge to the client. Your machine signs the challenge with the Private Key, and the server verifies the signature with the stored Public Key — all without transmitting any password over the network.

💡 Note: The two most common SSH key types are RSA 4096-bit and Ed25519. Ed25519 is preferred in 2026 for its shorter key size and faster verification.

2. Why Use SSH Keys Instead of Passwords?

ComparisonPassword LoginSSH Key Login
Brute Force Protection❌ High risk✅ Impossible to brute-force
ConvenienceType password every time✅ No typing (with SSH Agent)
Phishing Risk❌ Password can be stolen✅ Key never transmitted
Multi-server AccessRemember multiple passwords✅ One key for many servers
Audit & Access ControlHard to attribute logins✅ Identify each user by key
Man-in-the-Middle Protection❌ Risky if TOFU fails✅ Host Key Pinning prevents it

Shodan data shows SSH-accessible servers receive thousands of Brute Force attempts per day. Switching to SSH Key authentication and disabling password login immediately closes this attack vector.

3. How SSH Key Authentication Works

The SSH Key authentication process uses Asymmetric Cryptography:

  1. Client connects to the server via Port 22 (or a custom port).
  2. Server sends a random challenge to the client.
  3. Client signs the challenge using its Private Key.
  4. Server verifies the signature against the stored Public Key in authorized_keys.
  5. If matched — access is granted immediately. No password is ever transmitted.
⚠️ Warning: Your Private Key is the "master key" to your server. If lost or stolen, immediately remove the corresponding Public Key from all servers and generate a new key pair.

4. Generating an SSH Key Pair

1Open Terminal (macOS/Linux)

Generate an Ed25519 key (recommended for 2026):

ssh-keygen -t ed25519 -C "[email protected]"

Or for RSA 4096-bit:

ssh-keygen -t rsa -b 4096 -C "[email protected]"
2Answer the Prompts
Enter file in which to save the key (/home/user/.ssh/id_ed25519): [Press Enter]
Enter passphrase (empty for no passphrase): [Enter a passphrase or press Enter to skip]
Enter same passphrase again: [Confirm passphrase]

It's strongly recommended to use a passphrase. If someone obtains your Private Key file, they still need the passphrase to use it.

3Files Generated
~/.ssh/id_ed25519      # Private Key — keep ONLY on your machine
~/.ssh/id_ed25519.pub  # Public Key — upload to servers

View your Public Key:

cat ~/.ssh/id_ed25519.pub

5. Uploading Your Public Key to the Server

Method 1: Using ssh-copy-id (Easiest)

ssh-copy-id -i ~/.ssh/id_ed25519.pub username@your-vps-ip

This command uses password login one last time to copy your Public Key to the server's ~/.ssh/authorized_keys automatically.

Method 2: Manual Copy

# 1. View your Public Key
cat ~/.ssh/id_ed25519.pub

# 2. Log in to the server
ssh username@your-vps-ip

# 3. Create the directory and file if they don't exist
mkdir -p ~/.ssh
chmod 700 ~/.ssh

# 4. Paste your Public Key
echo "ssh-ed25519 AAAA...xxx [email protected]" >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

Test Your Key Login (Keep Existing Session Open!)

# Open a NEW terminal and test
ssh -i ~/.ssh/id_ed25519 username@your-vps-ip

If you log in without being prompted for a password (or just the Key passphrase), you're ready to proceed.

6. Configuring sshd_config for Security

Edit /etc/ssh/sshd_config on the server:

sudo nano /etc/ssh/sshd_config

Verify and set the following options:

# Confirm Public Key Auth is enabled
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys

# Disable direct Root login
PermitRootLogin no

# Limit auth attempts
MaxAuthTries 3

# Change Port (optional — reduces Bot noise)
# Port 2222

# Disable X11 Forwarding (if not needed)
X11Forwarding no
💡 Tip: Changing the SSH port (e.g., to 2222) doesn't add meaningful security but does reduce log noise from bots scanning Port 22. If you change the port, remember to allow the new port in your firewall.

7. Disabling Password Authentication

Only do this after confirming that SSH Key login works successfully. Do not close your existing session first!

⚠️ Critical Warning: Never disable Password Authentication before verifying SSH Key login works. If done in the wrong order, you will lock yourself out of the server.
# In /etc/ssh/sshd_config
PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM no

Save the file and restart the SSH service:

# Ubuntu/Debian
sudo systemctl restart ssh

# CentOS/Rocky Linux
sudo systemctl restart sshd

Open a new terminal and verify you can still log in — and that password login is now rejected:

ssh -o PasswordAuthentication=yes username@your-vps-ip
# Expected: Permission denied (publickey)

8. Setup Guide for Windows Users

Method 1: OpenSSH in PowerShell (Windows 10/11)

# Open PowerShell and run
ssh-keygen -t ed25519

# View your Public Key
type $env:USERPROFILE\.ssh\id_ed25519.pub

# Copy to server
ssh-copy-id -i $env:USERPROFILE\.ssh\id_ed25519.pub username@your-vps-ip

Method 2: PuTTY + PuTTYgen

  1. Open PuTTYgen → Select EdDSA or RSA 4096.
  2. Click Generate and move your mouse to generate randomness.
  3. Copy the Public Key from the top field and paste it into authorized_keys on the server.
  4. Save the Private Key as a .ppk file.
  5. In PuTTY settings: Connection → SSH → Auth → browse to your .ppk file.

9. Managing Multiple SSH Keys

When working with multiple servers, use the ~/.ssh/config file:

# ~/.ssh/config
Host my-vps-th
    HostName 203.0.113.10
    User ubuntu
    IdentityFile ~/.ssh/id_ed25519_vps_th

Host my-vps-sg
    HostName 198.51.100.20
    User root
    IdentityFile ~/.ssh/id_ed25519_vps_sg
    Port 2222

Connect using aliases:

ssh my-vps-th
ssh my-vps-sg

SSH Agent — Avoid Re-entering Passphrase

# Start SSH Agent
eval "$(ssh-agent -s)"

# Add key to Agent
ssh-add ~/.ssh/id_ed25519

# List loaded keys
ssh-add -l

10. Troubleshooting Common Issues

ProblemCauseSolution
Permission denied (publickey)Key not found or wrong permissionschmod 700 ~/.ssh, chmod 600 ~/.ssh/authorized_keys
Bad permissions on .sshDirectory permissions too openchmod 700 ~/.ssh
Host key verification failedHost key changed (server reprovisioned)ssh-keygen -R your-vps-ip
Connection refusedSSH service not running or firewall blockingCheck sudo systemctl status ssh and firewall rules
Warning: Unprotected private keyPrivate key file permissions too openchmod 600 ~/.ssh/id_ed25519

Debug SSH Connection

# Add -v for verbose output
ssh -v username@your-vps-ip

# -vvv for full debug output
ssh -vvv username@your-vps-ip

11. Frequently Asked Questions (FAQ)

Q: What is SSH Key Authentication?
SSH Key Authentication uses a cryptographic key pair (Public/Private Key) instead of passwords. The Private Key mathematically signs challenges from the server, which are verified with the stored Public Key — no password is ever sent over the network, making Brute Force attacks impossible.
Q: Is SSH Key safer than a strong password?
Yes. An Ed25519 key is computationally impossible to brute-force with modern hardware. Even a very strong password is far weaker than an SSH key. Once password authentication is disabled, automated bots attempting Brute Force attacks have no viable path to access.
Q: What if I lose my Private Key?
You will be locked out if password authentication is disabled. Access the server through your VPS provider's web console or VNC, then add a new Public Key to authorized_keys. Always maintain secure backups of your Private Key (e.g., an encrypted USB drive or password manager).
Q: Should I use RSA or Ed25519?
Ed25519 is recommended. It offers equivalent security to RSA 4096-bit with shorter key size, faster operations, and is supported by all modern Linux systems. Use RSA only when connecting to legacy systems that don't support Ed25519.
Q: Can I set up SSH Key authentication on Windows?
Yes. Windows 10 and 11 include OpenSSH built-in. Open PowerShell and run ssh-keygen -t ed25519 to generate a key pair. You can also use PuTTY with PuTTYgen as an alternative.
Q: What else should I do after setting up SSH Keys?
After SSH Key setup: (1) Install Fail2Ban to block IPs with repeated failed attempts, (2) Configure UFW firewall to allow only necessary ports, (3) Optionally change SSH port from 22 to reduce bot noise, (4) Keep your OS updated with security patches.

12. Summary

Setting up SSH Key Authentication is a fundamental security step that should be done immediately after provisioning any VPS. Key benefits include:

Ready to Deploy a Secure VPS?

AsiaGB.com offers Thailand and Singapore VPS with SSD storage, 99% Uptime, and Thai-language support.

View VPS Packages