Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Connect to Your VPS Securely with an SSH Key

Use an SSH key pair instead of a password to protect the main door of your server.

VPS and Cloud Servers2 min read13 steps2 screenshots

Why secure SSH

SSH (Secure Shell) is the way you manage your VPS from far away. A secure SSH connection:

  • Encrypts your login and your commands.
  • Keeps strangers out of the server.
  • Stops others from misusing your server for attacks.
  • Helps keep your services running.

An SSH key pair is much stronger than a password. The private key stays on your computer. The public key goes on the server.

Steps

  1. Create the key pair on your computer if you do not have one yet:
ssh-keygen -t ed25519
  1. Copy the public key to the server. Replace the user and IP:
ssh-copy-id username@server_IP

If ssh-copy-id is missing, paste the content of your .pub file into ~/.ssh/authorized_keys on the server.

  1. Connect with your private key.

OpenSSH (Linux and macOS)

  1. Open a terminal.
  2. Run:
ssh -i /path/to/private_key username@server_IP
Connecting with OpenSSH
  1. If the key has a passphrase, type it when asked.

PuTTY (Windows)

  1. Download and install PuTTY from its official website. If your key is in OpenSSH format, convert it with PuTTYgen first.
    PuTTY settings
  2. Open PuTTY. Enter the server IP or domain in Host Name.
  3. In the left panel, go to Connection, SSH, Auth.
  4. Click Browse next to Private key file for authentication and pick your .ppk file.
  5. Go back to Session, and (optional) save the session under a name.
  6. In Connection, Data, enter the user name in Auto-login username.
  7. Click Open. Enter the passphrase if you set one.

Harden the server

After the key login works, edit /etc/ssh/sshd_config on the server:

PasswordAuthentication no
PermitRootLogin no

Reload SSH:

sudo systemctl reload sshd
Warning: Keep your current session open and test a new login in a second window before you close it. Otherwise a mistake can lock you out.

Quick recap

  • Use an SSH key pair, not a password.
  • Copy the public key to the server, keep the private key safe.
  • Turn off password and root logins when the key works.