EQVPS

How to set up SSH key authentication on a VPS

Replace password logins with an SSH key pair: generate a key, copy the public half to your server, test it, and turn password login off. The single biggest security win for any new VPS, in a few commands.

Password logins are the weakest part of a fresh server: bots scan the internet and hammer port 22 with guesses around the clock. Swapping passwords for an SSH key pair removes that attack surface entirely, and it's the first thing worth doing on any new VPS. Here's the whole process in a few commands.

How SSH keys work

You generate a pair: a private key that stays on your computer and a public key you place on the server. The server challenges anyone connecting; only the holder of the matching private key can answer. You can hand out the public key freely — it's the private key you protect.

1. Generate a key pair (on your own computer)

ssh-keygen -t ed25519 -C "you@example.com"
# press Enter to accept the default path (~/.ssh/id_ed25519)
# set a passphrase for extra safety, or leave empty

This creates two files: ~/.ssh/id_ed25519 (private — never share) and ~/.ssh/id_ed25519.pub (public).

2. Copy the public key to your server

The easy way, if you can still log in with a password:

ssh-copy-id root@YOUR.SERVER.IP

No ssh-copy-id? Do it by hand:

cat ~/.ssh/id_ed25519.pub | ssh root@YOUR.SERVER.IP \
  "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"

3. Test the key before changing anything

Open a new terminal and log in — you shouldn't be asked for the server password:

ssh root@YOUR.SERVER.IP

If that works, keep this session open while you do the next step, so a mistake can't lock you out.

4. Turn off password login

On the server, edit /etc/ssh/sshd_config:

sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config
sudo systemctl restart ssh    # on some distros the service is named sshd

From now on only your key gets in, and the constant brute-force noise on port 22 simply bounces off.

Honest cautions

Next steps

An SSH key is step one of a hardened server. Pair it with a firewall — see how to configure a UFW firewall and how to set up fail2ban — and run the full new-VPS security checklist before exposing anything. On a no-KYC crypto-paid VPS, a key is also how you keep access truly yours.

FAQ

Why use an SSH key instead of a password?

A password can be guessed or brute-forced; bots hammer port 22 constantly. An SSH key pair is effectively impossible to guess, and once you disable password login those brute-force attempts simply fail. It's also more convenient — you log in without typing a password each time.

What's the difference between the public and private key?

The pair is generated together. The private key (id_ed25519) stays on your own computer and is never shared. The public key (id_ed25519.pub) is copied to the server. Anyone can hold your public key safely; only the matching private key can log in, so guard the private one.

ed25519 or RSA — which should I generate?

ed25519 for anything modern: shorter keys, faster, and secure. Use RSA (at least 4096-bit) only if you must connect to old systems that don't support ed25519. The commands below use ed25519.

What if I lose my private key?

You lose that route in. If password login is still on, use it to add a new key; if you disabled it, use your provider's console (EQVPS has a browser console) to get in and add a new public key. Keep a backup of your private key, and consider adding a second key so one loss isn't a lockout.

Is it safe to disable password login entirely?

Yes — once your key works and you've confirmed you can log in with it. Test the key in a second terminal before closing your current session, so a mistake never locks you out. After that, disabling passwords removes the entire brute-force attack surface.

Comments

No comments yet. Be the first.

Leave a comment

Comments are moderated before they appear.