EN

Linux and networking

Connect over SSH with an Ed25519 key

Create an Ed25519 SSH key, install it on your Linux server, test it, then disable password login without locking yourself out.

8 min read, updated on 18 November 2026

On this page

Your values

Enter them once and the commands in this guide update.

An SSH key replaces the password with a pair of files: a private key, which stays on your computer, and a public key, which you place on the server. Once passwords are disabled, the bots that try combinations on the SSH port have nothing left to guess.

This guide follows a precise order so that you do not lock yourself out: create the key, install it, test it, and only then disable the password.

Prerequisites

  • A Linux server you can reach over SSH with a password. If that is not the case yet, follow Connect to your Linux server over SSH
  • The account password, which you still need for the emergency console
  • A fallback access: on a VPS, the NoVNC console in your client area. If your plan does not include one, ask support how to reach the server if you get locked out before you disable the password
  • A terminal on your computer: PowerShell on Windows, Terminal on macOS or Linux

In the commands, replace YOUR_USER with your username and YOUR_SERVER_IP with the server's IP address. If your SSH port is not 22, add -p followed by the port to the ssh and ssh-copy-id commands.

Step 1: create the key on your computer

Run this command on your computer, not on the server. It is the same on Windows, macOS and Linux:

Terminal
ssh-keygen -t ed25519 -C "my-computer"

The text after -C is a simple comment that helps you recognize the key.

  1. Press Enter to accept the suggested location.
  2. Choose a passphrase. It encrypts the private key: anyone who copies the file cannot use it without the passphrase.

Two files are created in the .ssh folder of your account, ~/.ssh on macOS and Linux, C:\Users\YourName\.ssh on Windows:

File Role Can it be shared?
id_ed25519 Private key Never, neither by email nor in a ticket
id_ed25519.pub Public key Yes, this is the one that goes on the server

Step 2: install the public key on the server

Connect with the account you will use afterwards: the key only applies to that account.

From macOS or Linux

Terminal
ssh-copy-id -i ~/.ssh/id_ed25519.pub YOUR_USER@YOUR_SERVER_IP

Enter your password. The message Number of key(s) added: 1 confirms the addition.

From Windows

ssh-copy-id does not ship with Windows. Run this command in PowerShell:

PowerShell
Get-Content "$env:USERPROFILE\.ssh\id_ed25519.pub" | ssh YOUR_USER@YOUR_SERVER_IP "umask 077; mkdir -p ~/.ssh; tr -d '\r' >> ~/.ssh/authorized_keys; chmod 700 ~/.ssh; chmod 600 ~/.ssh/authorized_keys"

It appends the key to the authorized_keys file, removes Windows line endings and applies the correct permissions.

Check the installation

Compare your key's fingerprint with those on the server. On your computer:

Terminal
ssh-keygen -lf ~/.ssh/id_ed25519.pub

On Windows:

PowerShell
ssh-keygen -lf "$env:USERPROFILE\.ssh\id_ed25519.pub"

Then, in your session on the server:

Terminal
ssh-keygen -lf ~/.ssh/authorized_keys

The same SHA256:... fingerprint must appear on both sides.

Step 3: test the key login

In a new window, connect with passwords forbidden:

Terminal
ssh -o PreferredAuthentications=publickey -o PasswordAuthentication=no YOUR_USER@YOUR_SERVER_IP
  • The message Enter passphrase for key is normal: enter your key's passphrase.
  • If you reach the server, the key works.
  • If you get Permission denied (publickey), stop here and see Troubleshooting. Do not disable the password.

Avoid retyping the passphrase

The SSH agent keeps the key unlocked during your session.

On macOS, the passphrase is stored in the keychain:

Terminal
ssh-add --apple-use-keychain ~/.ssh/id_ed25519

On Linux:

Terminal
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

On Windows, in PowerShell opened as administrator:

PowerShell
Get-Service ssh-agent | Set-Service -StartupType Automatic
Start-Service ssh-agent
ssh-add "$env:USERPROFILE\.ssh\id_ed25519"

Step 4: disable password login

Before continuing, check these three points:

  • Key login worked in a new window
  • Your first SSH session is still open
  • You have your fallback access and the account password

The following commands run on the server as root. With another account, switch to root first:

Terminal
sudo -i

Check the configuration folder

Terminal
grep -i '^Include' /etc/ssh/sshd_config

The expected result is Include /etc/ssh/sshd_config.d/*.conf. If nothing is displayed, go to the variant without a configuration folder.

Create the configuration file

Terminal
cat > /etc/ssh/sshd_config.d/00-key-only.conf <<'EOF'
PasswordAuthentication no
KbdInteractiveAuthentication no
EOF
chmod 644 /etc/ssh/sshd_config.d/00-key-only.conf

Check before applying

First check the syntax. The command must display nothing:

Terminal
sshd -t

Then display the configuration actually in effect:

Terminal
sshd -T | grep -Ei '^(passwordauthentication|kbdinteractiveauthentication|pubkeyauthentication|permitrootlogin)'

You should get passwordauthentication no, kbdinteractiveauthentication no and pubkeyauthentication yes. If you log in as root, permitrootlogin must not be no.

Apply the change

On Debian and Ubuntu:

Terminal
systemctl restart ssh

On AlmaLinux, Rocky Linux, CentOS and Fedora:

Terminal
systemctl restart sshd

Your open session normally stays active.

Variant without a configuration folder

If sshd_config has no Include line, open it:

Terminal
nano /etc/ssh/sshd_config

Add these lines at the very top of the file, then save. Next, run sshd -t, sshd -T and the restart as above.

Text
PasswordAuthentication no
KbdInteractiveAuthentication no

Step 5: check the result

Keep your first session open and run these two tests in a new window.

Key login must succeed:

Terminal
ssh YOUR_USER@YOUR_SERVER_IP

Password login must fail:

Terminal
ssh -o PubkeyAuthentication=no -o PreferredAuthentications=password YOUR_USER@YOUR_SERVER_IP

The expected result is:

Text
YOUR_USER@YOUR_SERVER_IP: Permission denied (publickey).

If both tests pass, you can close your first session. To go further, see Secure your server.

Roll back

From the session still open, or from the NoVNC console, delete the file you created and restart the service. Replace ssh with sshd depending on your system.

Terminal
rm /etc/ssh/sshd_config.d/00-key-only.conf
sshd -t
systemctl restart ssh

To open the console: in your client area, open your service page, click the terminal-shaped icon at the top right, choose NoVNC Console graphique (NoVNC graphical console), confirm with Ok, then click Connecter (Connect). Log in with the account password. The console keyboard layout may differ from yours.

If you edited sshd_config directly, remove the two lines you added.

Manage your keys

  • Several computers: create one key per device and add each public key to the server. You can then remove one without affecting the others.
  • Remove an access: delete the matching line in ~/.ssh/authorized_keys, for example after losing a computer.
  • Backup: keep a copy of the private key somewhere safe, such as a password manager. A forgotten passphrase cannot be recovered: you will have to create a new key.

Troubleshooting

Permission denied (publickey)

The server rejects your key. Check the following, in order:

  1. The username: the key must be installed on that account.
  2. The key offered by your computer:
Terminal
ssh -v YOUR_USER@YOUR_SERVER_IP

Look for the lines Offering public key and Server accepts key.

  1. The permissions on the server, from a session opened with the account concerned:
Terminal
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chown -R "$(id -un):$(id -gn)" ~/.ssh
chmod go-w ~
  1. On AlmaLinux, Rocky Linux, CentOS and Fedora, the SELinux context:
Terminal
restorecon -Rv ~/.ssh
  1. The server logs, with sshd instead of ssh depending on the system:
Terminal
journalctl -u ssh -n 50 --no-pager

A message such as Authentication refused: bad ownership or modes points to a permissions problem.

The server still asks for a password

If the message is YOUR_USER@YOUR_SERVER_IP's password:, the key was not accepted and the password is still active. Check the key as described above, then run the sshd -T command from step 4 again. If passwordauthentication yes remains, make sure your file ends in .conf, that the service was restarted and that no other file has a prefix sorted before 00-.

Do not confuse this with Enter passphrase for key, which asks for the passphrase of your local key.

UNPROTECTED PRIVATE KEY FILE!

Your private key is readable by other accounts, so the client refuses to use it. On macOS and Linux:

Terminal
chmod 600 ~/.ssh/id_ed25519

On Windows:

PowerShell
icacls "$env:USERPROFILE\.ssh\id_ed25519" /inheritance:r /grant:r "${env:USERNAME}:F"

Too many authentication failures

Your agent offers too many keys. Specify the one to use:

Terminal
ssh -o IdentitiesOnly=yes -i ~/.ssh/id_ed25519 YOUR_USER@YOUR_SERVER_IP

Could not open a connection to your authentication agent

The SSH agent is not running. Go back to the commands in Avoid retyping the passphrase.

sshd: command not found

The /usr/sbin folder is not in your path. Switch to root with sudo -i, or use the full path /usr/sbin/sshd.

You no longer have access to the server

Open the NoVNC console and follow Roll back. If you cannot log in there, open a ticket from your client area. Never send your private key or your password.