How to Set Up SSH Key Authentication
Create a key pair on your computer with ssh-keygen, add the public key to ~/.ssh/authorized_keys on your VPS, then test it in a new window while your current session stays open. Keep the private key on your computer and protect it with a passphrase.
Applies to: Linux OpenSSH Blue Arctic VPS Hosting and Virtual Dedicated Servers (VDS); Windows, macOS and Linux computers
On this page
An SSH key is a pair of files. The private key stays on your computer and works like a password that can’t be guessed. The public key goes on the server. This guide adds a key alongside your password; it doesn’t switch password login off.
Before you start
- Warning: connect to your VPS as the user who will use the key, and keep that window open until you’ve tested the key. It’s your way back in if something goes wrong.
- If your VPS has cPanel/WHM or Plesk, the panel may manage SSH keys too. Not sure which to use? Open a support ticket first.
- Your plan includes Core Managed, so open a support ticket before you change any other SSH or firewall settings.
- Replace
username,203.0.113.10andPORTwith the login details we gave you when your server was set up. If your port is 22, leave out-p PORT.
Step 1: Create a key on your computer
Warning
if a key already exists, ssh-keygen asks Overwrite (y/n)?. Always type n and press Enter: y destroys your existing key. Use that key and skip to Step 2.
- Open a new PowerShell window (Windows) or Terminal window (Mac or Linux) on your own computer. Don’t use the window that’s connected to your server.
- Run this. It creates the key pair on your computer only;
-Cadds a label to help you recognize the key.ssh-keygen -t ed25519 -C "you@yourdomain.com"
- Press Enter to accept the suggested file location.
- Type a passphrase and press Enter, then type it again. Nothing appears while you type. Keep the passphrase safe, such as in a password manager: it can’t be recovered.
You now have id_ed25519 (the private key: never share it, even with us) and id_ed25519.pub (the public key, which you copy) in the .ssh folder in your home folder.
Step 2: Add the public key to your VPS
On a Mac or Linux computer
- In the window from Step 1, run this. It adds your public key to
~/.ssh/authorized_keyson the server and keeps keys already there.ssh-copy-id -i ~/.ssh/id_ed25519.pub -p PORT username@203.0.113.10
- Type your server password when asked. You’ll see
Number of key(s) added: 1.
On Windows
- In the PowerShell window from Step 1, run this to copy your public key to the clipboard:
Get-Content $env:USERPROFILE\.ssh\id_ed25519.pub | Set-Clipboard
- Switch to the window that’s connected to your server.
- Run
mkdir -p ~/.ssh. This creates the.sshfolder if it’s missing. - Run
chmod 700 ~/.ssh. This lets only you open the folder. - Warning: this command needs two
>signs; with one, it would erase the keys already in the file. Runcat >> ~/.ssh/authorized_keys. The cursor waits on an empty line. - Press Enter once. Then right-click in the window to paste your key, and press Enter again. (The extra empty line is harmless; it makes sure your key starts on its own line.)
- Press Ctrl+D. This saves the key and brings your prompt back.
- Run
chmod 600 ~/.ssh/authorized_keys. This lets only you change the file; the server ignores a file others can change.
Step 3: Test in a second window
- Leave the window that’s connected to your server open.
- Open a new PowerShell or Terminal window and connect as usual, for example
ssh -p PORT username@203.0.113.10. - If you see
Enter passphrase for key, type your key’s passphrase and press Enter. If you seeusername@203.0.113.10's password:instead, the key isn’t working: press Ctrl+C and see Troubleshooting.
How to tell it worked
You’re logged in without typing the server password. Now you can close the first window.
How to undo it
Warning
if the server doesn’t accept your password, removing your key can lock you out. First, in a new window, check that password login still works: ssh -o PubkeyAuthentication=no -p PORT username@203.0.113.10. If it doesn’t, keep the key and open a support ticket.
- In your open session, run
nano ~/.ssh/authorized_keys(a simple editor). If you seenano: command not found, open a support ticket. - Use the arrow keys to move to the line that ends with your label, for example
you@yourdomain.com. - Press Ctrl+K once to remove that line. Don’t change any other line: other lines may be keys that other people or tools use.
- Press Ctrl+O, then Enter to save, then Ctrl+X to exit.
Troubleshooting
- You’re still asked for the server password: the key wasn’t added for this user. Check you used the same username in Steps 2 and 3. The server also ignores the key if other users can change your files: in your open session, run
chmod go-w ~,chmod 700 ~/.sshandchmod 600 ~/.ssh/authorized_keys. - Pasting the key doesn’t work: press Ctrl+C in the server window and open a support ticket.
- You lost the private key or think someone copied it: remove its line from
authorized_keys(see How to undo it) and create a new key.
Still need help?
Open a support ticket from the Client Portal at my.bluearctic.com. Our support page explains how the 24/7 helpdesk works. Include your VPS IP address, the username, the output of your connection attempt with -v added, and what you already tried. You may paste your public key (the one line in the .pub file); it’s safe to share. Never share your private key (the file without .pub). Never include a password.