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.
- Before you change any other SSH or firewall settings, open a support ticket: a wrong setting can lock you out. We’ll tell you whether the work is covered by your plan.
- 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 your .ssh 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. Lines that start with
INFO:are normal. Near the end you’ll seeNumber of key(s) added:followed by1.
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.
- Check the paste: one long line (it may wrap onto a second row) that starts with
ssh-ed25519and ends with your label. If it looks right, press Enter. If not, press Ctrl+C and start this list again. - 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.
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, make a copy first:
cp -p ~/.ssh/authorized_keys ~/.ssh/authorized_keys.backup. - Run
awk '{print NR, $NF}' ~/.ssh/authorized_keys. It only reads: it prints each line’s number and last word (the key’s label; a key with no label shows as a long run of letters, and an empty line shows only its number). - Note the number in front of your label (the last word in your
.pubfile), for example4 you@yourdomain.com. If your label is missing or appears twice, stop and open a support ticket. - Run
nano +4 ~/.ssh/authorized_keyswith your number in place of 4. This opens the nano editor with the cursor on that line. If you seenano: command not found, open a support ticket. - Press Ctrl+E. The line’s end should show your label; if not, press Ctrl+X to leave.
- Press Ctrl+K once to remove that line. Don’t change any other line.
- Press Ctrl+O, then Enter to save, then Ctrl+X to exit.
- Run the awk command from step 2 of this list again. Your label should be gone and the other lines unchanged. If the wrong line went, put the copy back:
cp -p ~/.ssh/authorized_keys.backup ~/.ssh/authorized_keys.
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. - 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. Never share your private key (the file without .pub). Never include a password.