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.
SSH Key Authentication is an authentication method that uses a cryptographic key pair consisting of:
~/.ssh/authorized_keys.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.
RSA 4096-bit and Ed25519. Ed25519 is preferred in 2026 for its shorter key size and faster verification.
| Comparison | Password Login | SSH Key Login |
|---|---|---|
| Brute Force Protection | ❌ High risk | ✅ Impossible to brute-force |
| Convenience | Type password every time | ✅ No typing (with SSH Agent) |
| Phishing Risk | ❌ Password can be stolen | ✅ Key never transmitted |
| Multi-server Access | Remember multiple passwords | ✅ One key for many servers |
| Audit & Access Control | Hard 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.
The SSH Key authentication process uses Asymmetric Cryptography:
authorized_keys.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]"
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.
~/.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
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.
# 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
# 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.
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
Only do this after confirming that SSH Key login works successfully. Do not close your existing session first!
# 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)
# 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
authorized_keys on the server..ppk file..ppk file.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
# Start SSH Agent
eval "$(ssh-agent -s)"
# Add key to Agent
ssh-add ~/.ssh/id_ed25519
# List loaded keys
ssh-add -l
| Problem | Cause | Solution |
|---|---|---|
| Permission denied (publickey) | Key not found or wrong permissions | chmod 700 ~/.ssh, chmod 600 ~/.ssh/authorized_keys |
| Bad permissions on .ssh | Directory permissions too open | chmod 700 ~/.ssh |
| Host key verification failed | Host key changed (server reprovisioned) | ssh-keygen -R your-vps-ip |
| Connection refused | SSH service not running or firewall blocking | Check sudo systemctl status ssh and firewall rules |
| Warning: Unprotected private key | Private key file permissions too open | chmod 600 ~/.ssh/id_ed25519 |
# Add -v for verbose output
ssh -v username@your-vps-ip
# -vvv for full debug output
ssh -vvv username@your-vps-ip
Setting up SSH Key Authentication is a fundamental security step that should be done immediately after provisioning any VPS. Key benefits include: