Debian and Ubuntu Linux: Set openssh SeverKeyBits to 1024

Published on 2013/11/01, by in linux, sysadmin.



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



Change

ServerKeyBits 768



to:

ServerKeyBits 1024




Save and close.

ssh_1024


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



Done!



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@172.16.1.102
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
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
2a:0e:ae:d9:03:8b:0b:37:60:66:4f:ff:06:41:05:c6.
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 162.243.76.159 has changed and you have requested strict checking.
Host key verification failed.




Links to bug reports: Ubuntu | Debian



3 Responses

  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 *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

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

Home linux Debian and Ubuntu Linux: Set openssh SeverKeyBits to 1024