Using Ed25519 for OpenSSH keys (instead of DSA/RSA/ECDSA)

Introduction into Ed25519

OpenSSH 6.5 added support for Ed25519 as a public key type. It is using an elliptic curve signature scheme, which offers better security than ECDSA and DSA. At the same time, it also has good performance. This type of keys may be used for user and host keys. With this in mind, it is great to be used together with OpenSSH. In this article, we have a look at this new key type.


Many forum threads have been created regarding the choice between DSA or RSA. DSA is being limited to 1024 bits, as specified by FIPS 186-2. This is also the default length of ssh-keygen. While the length can be increased, it may not be compatible with all clients. So it is common to see RSA keys, which are often also used for signing. With Ed25519 now available, the usage of both will slowly decrease.

Configuring the server

The first thing to check is if your current OpenSSH package is up-to-date. You will need at least version 6.5 of OpenSSH.

ssh -V

Recreate the SSH host keys

Next step is creating the keys for the SSH daemon.

cd /etc/ssh

Optionally make a copy of the existing host keys

mkdir backup && mv ssh_host_* ./backup/

Then create the key pair using Ed25519.

# ssh-keygen -f /etc/ssh/ssh_host_ed25519_key -N '' -t ed25519
Generating public/private ed25519 key pair.
Your identification has been saved in etc/ssh/ssh_host_ed25519_key.
Your public key has been saved in etc/ssh/
The key fingerprint is:
96:67:0f:50:8d:16:51:c2:47:9c:4e:85:b4:79:bd:6b root@arch
The key's randomart image is:
+--[ED25519 256]--+
|         .=X++.  |
|         .+.Bo . |
|        .. +o . .|
|         o  ..  .|
|        S +    . |
|       . o o    .|
|            .  E |
|              .  |
|                 |

Change SSH configuration (server)

Next step is changing the /etc/ssh/sshd_config file. Add the new host key type:

HostKey /etc/ssh/ssh_host_ed25519_key

Remove any of the other HostKey settings that are defined.

Client Configuration

After configuring the server, it is time to do the client. We have to create a new key first. Make sure that your ssh-keygen is also up-to-date, to support the new key type. Note: the tilde (~) is an alias for your home directory and expanded by your shell.

$ ssh-keygen -t ed25519 -C ""
 Generating public/private ed25519 key pair.
 Enter file in which to save the key (/home/michael/.ssh/id_ed25519):
 Enter passphrase (empty for no passphrase):
 Enter same passphrase again:
 Your identification has been saved in /home/michael/.ssh/id_ed25519.
 Your public key has been saved in /home/michael/.ssh/
 The key fingerprint is:
 The key's randomart image is:
 +--[ED25519 256]--+
 |                 |
 |          .      |
 |    . .  . .     |
 |   . o .  o o    |
 |    o . S= . + . |
 |   . o  o + o o .|
 |  . . .. o o .  .|
 |   . .  E o     .|
 |      ..   ....o.|

Optional step: Check the key before copying it.

ssh-keygen -l -f ~/.ssh/id_ed25519

If that looks good, copy it to the destination host.

ssh-copy-id -i ~/.ssh/ michael@

Then determine if we can log in with it.

$ ssh -i ~/.ssh/id\_ed25519 michael@
Enter passphrase for key '~/.ssh/id\_ed25519':`

When using this newer type of key, you can configure to use it in your local SSH configuration file (~/.ssh/config). Defining the key file is done with the IdentityFile option.

Host [name]
HostName [hostname]
User [your-username]
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes

Relevant commands in this article

Like to learn more about the commands that were used in this article? Have a look, for some there is also cheat sheet available.


Small picture of Michael Boelen

This article has been written by our Linux security expert Michael Boelen. With focus on creating high-quality articles and relevant examples, he wants to improve the field of Linux security. No more web full of copy-pasted blog posts.

Discovered outdated information or have a question? Share your thoughts. Thanks for your contribution.

Mastodon icon