GuidesServer

Tutorial: logging in to a server with an SSH key

By the Banzai Labs teamUpdated on 2 min read

Before you start

You need a Linux server reachable over SSH with a password, and a terminal. In the examples, the user is deploy and the address 203.0.113.10: replace them with your own.

1. Create the key on your computer

ssh-keygen -t ed25519 -C "laptop-2026"

Accept the suggested location and choose a passphrase. Two files are created in ~/.ssh/: id_ed25519, the private key, which never leaves your machine, and id_ed25519.pub, the public key, which you give to the server.

2. Send the public key to the server

ssh-copy-id deploy@203.0.113.10

The command asks for the password one last time and adds the key to the server’s ~/.ssh/authorized_keys file.

3. Test

ssh deploy@203.0.113.10

The connection must open without asking for the server password. Keep this session open for what follows.

4. Turn off password login

On the server, open /etc/ssh/sshd_config and set this line:

PasswordAuthentication no

Check the file, then reload the service:

sudo sshd -t
sudo systemctl reload ssh

On some distributions the service is called sshd. Before closing the open session, open a second one in another terminal: if it gets in, you are done.

If the key is refused

  • File permissions: ~/.ssh must be 700 and authorized_keys 600, owned by the right user.
  • The wrong user: the key is installed for one specific account, not for all.
  • The detail of the failure: ssh -v deploy@203.0.113.10 shows which key is offered and why it is rejected.

For the rest of a server set-up, read Hosting on a VPS.

Frequently asked questions

Why a key rather than a password?
An exposed server receives a constant stream of password login attempts. A key cannot be guessed, and once passwords are turned off those attempts all fail.
Should I put a passphrase on the key?
Yes. It protects the key if the computer is stolen or copied. Your system’s SSH agent remembers it for the session.
What if I lose my key?
Use your host’s rescue console to install a new one. This is why you install one key per device, rather than a single key copied everywhere.

Read next

All guides