How to Connect to a VPS with SSH and Set Up SSH Keys

SSH (Secure Shell) is how you log in to a VPS from your own computer. This page shows how to connect with a password, then how to switch to SSH keys, which are safer and save you typing.

Step 1: Connect with SSH

Linux and macOS have an SSH client built in; on Windows 10 and 11 it is in PowerShell and the Command Prompt, and you can also use PuTTY. You need the server's IP address (or domain name) and a username:

ssh username@server_ip_address

For example, ssh [email protected]. The first time, you are asked to confirm the server's fingerprint; type yes, then enter your password.

Step 2: Generate a key pair

On your own computer (not the server), run:

ssh-keygen -t ed25519

Press Enter to accept the default location and choose a passphrase to protect the key. This creates a private key, which must stay secret, and a public key ending in .pub, which is safe to share.

Step 3: Copy the public key to the VPS

ssh-copy-id username@server_ip_address

Enter your password when asked. (On Windows without ssh-copy-id, paste the contents of the .pub file into ~/.ssh/authorized_keys on the server.)

Step 4: Test it

ssh username@server_ip_address

You should log in without the server's password (you may be asked for the key's passphrase). If you are still asked for a password, check that ~/.ssh is mode 700 and authorized_keys is mode 600 on the server.

Step 5: Turn off password logins (optional, recommended)

Once key login works, set PasswordAuthentication no in /etc/ssh/sshd_config and restart SSH. Keep your current session open while you test a new one, so a mistake cannot lock you out. More in the VPS security guide.

Need a server to connect to? Cheapest VPS plans in stock

In stock when this page loaded. See all 20 matching plans

More RackNerd guides