Debian and Ubuntu Linux: Set openssh SeverKeyBits to 1024

By | 2013/11/01

The upstream openssh project sets the value ServerKeyBits to 1024, but Debian and Ubuntu currently unfortunately have a lower security setting of 768 bits. I’ve filed a bug to fix this. In the meantime, here is how to make that change now!

1. First, edit the file /etc/ssh/sshd_config

$ sudo vim /etc/ssh/sshd_config


ServerKeyBits 768


ServerKeyBits 1024

Save and close.


2. Next you must first delete the existing host ssh keys and regenerate new ones.

$ sudo rm /etc/ssh/ssh_host_*
$ sudo dpkg-reconfigure openssh-server

The output will look similar to the following:

$ dpkg-reconfigure openssh-server 
Creating SSH2 RSA key; this may take some time ...
Creating SSH2 DSA key; this may take some time ...
Creating SSH2 ECDSA key; this may take some time ...
ssh stop/waiting
ssh start/running, process 1224


Be aware the next time you try to ssh to that server, your will get a warning that the host key changed- which it did! (It is also possible that a host key has just been changed.)

To resolve this, delete the old key from your ~/.ssh/known_hosts file and then reconnect.

$ ssh user@
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
Please contact your system administrator.
Add correct host key in /home/smiller/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/smiller/.ssh/known_hosts:129
ECDSA host key for has changed and you have requested strict checking.
Host key verification failed.

Links to bug reports: Ubuntu | Debian

3 thoughts on “Debian and Ubuntu Linux: Set openssh SeverKeyBits to 1024

  1. Reggle

    Thanks for the article! I had changed the hostkey setting myself already but couldn’t figure out how to generate a new one. This solves it.

  2. Naftuli Tzvi Kay

    My vote is that the package maintainers set it up with 2048 bits for the server keys. This makes more sense in a forward-thinking world.

    All of my machines use 4096 bits for server and client keys.

  3. Anonymous

    I stumbled about this setting myself today, so I figured I’d share the results of my research here.

    Actually, having ServerKeyBits at 768 probably doesn’t hurt much, since it is used for a type, which is used only with SSH protocol version 1 and nobody should be using that anymore anyway. There is also no point to regenerating the host keys, as the setting refers only to the ephemeral key, which is a temporary key and kept for at most 10 minutes after use, before the server generates a new one.


Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.