Set up SSH keys

Create an SSH key pair, add it to your Linux VPS from macOS, Linux or Windows, and optionally switch off password logins safely.

  • Intermediate
  • Linux VPS
  • 2 min read

By RunRacks Team · Published

SSH keys replace passwords with a key pair. The private key stays on your computer and the public key goes on the server. Keys are far harder to guess than any password, and once they are set up you log in without typing one.

1. Create a key pair on your computer

macOS, Linux and Windows 10 or 11 (PowerShell) all include OpenSSH. Run:

Terminal
ssh-keygen -t ed25519 -C "you@laptop"

Press Enter to accept the default file location. When asked, set a passphrase. It protects the key if your computer is ever stolen.

This creates two files in the .ssh folder in your home directory:

  • id_ed25519 is the private key. Never share it or upload it anywhere.
  • id_ed25519.pub is the public key. This one is safe to copy to servers.

2. Copy the public key to your server

On macOS and Linux:

Terminal
ssh-copy-id [email protected]

On Windows PowerShell, which has no ssh-copy-id:

PowerShell
type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh [email protected] "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"

Enter the server password one last time.

3. Test the key

Terminal
ssh [email protected]

You should be asked for your key's passphrase, if you set one, and not the server password.

4. Turn off password logins (optional)

Open the SSH server configuration:

Terminal
nano /etc/ssh/sshd_config

Set this line (remove the # in front if there is one):

Text
PasswordAuthentication no

Some images also set this option in a file under /etc/ssh/sshd_config.d/, and that file can override your change. Check with:

Terminal
grep -ri passwordauthentication /etc/ssh/sshd_config.d/

Check the configuration for mistakes, then reload SSH. On Debian and Ubuntu the service is called ssh. On RHEL-based systems it is sshd.

Terminal
sshd -t && systemctl reload ssh

Using more than one computer

Create a separate key on each device and add each public key as its own line in ~/.ssh/authorized_keys. If you lose a device, delete only that line.

Was this guide helpful?

Still stuck?

Ask RunRacks AI for a quick answer, or open a ticket and our team will take a look at your server.

Security

Check the Windows Firewall rule for RDP port 12230

Find and verify the inbound TCP 12230 rule that lets Remote Desktop reach your RunRacks server, recreate it if it was deleted and scope it without locking yourself out.

  • Intermediate
  • Windows VPS · Admin RDP
  • 5 min read

Security

iptables basics: list, allow, drop and save rules

Learn how iptables chains and rule order work, then build a small ruleset that allows SSH and web traffic, drops everything else and can be edited by line number.

  • Intermediate
  • Linux VPS
  • 6 min read