Raspbian (2015-11-21-raspbian-jessie.zip SHA1: ce1654f4b0492b3bcc93b233f431539b3df2f813) doesn't enable hardware random number generator by default. This causes generation of predictable SSH host keys on the first boot.
As soon as the systems starts up systemd-random-seed tries to seed /dev/urandom, but /var/lib/systemd/random-seed is missing, because it hasn't been created yet. /etc/rc2.d/S01regenerate_ssh_host_keys is executed, but /dev/urandom pool doesn't have that much entropy at this point and predictable SSH host keys will be created.
Original /etc/init.d/regenerate_ssh_host_keys (/etc/rc2.d/S01regenerate_ssh_host_keys is a symbolic link to it):
Code: Select all
#!/bin/sh
### BEGIN INIT INFO
# Provides: regenerate_ssh_host_keys
# Required-Start:
# Required-Stop:
# Default-Start: 2
# Default-Stop:
# Short-Description: Regenerate ssh host keys
# Description:
### END INIT INFO
. /lib/lsb/init-functions
set -e
case "$1" in
start)
log_daemon_msg "Regenerating ssh host keys (in background)"
nohup sh -c "yes | ssh-keygen -q -N '' -t dsa -f /etc/ssh/ssh_host_dsa_key && \
yes | ssh-keygen -q -N '' -t rsa -f /etc/ssh/ssh_host_rsa_key && \
yes | ssh-keygen -q -N '' -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key && \
yes | ssh-keygen -q -N '' -t ed25519 -f /etc/ssh/ssh_host_ed25519_key && \
systemctl enable ssh && sync && \
rm /etc/init.d/regenerate_ssh_host_keys && \
update-rc.d regenerate_ssh_host_keys remove && \
printf '\nfinished\n' && systemctl start ssh" > /var/log/regen_ssh_keys.log 2>&1 &
log_end_msg $?
;;
*)
echo "Usage: $0 start" >&2
exit 3
;;
esac
Code: Select all
#!/bin/sh
### BEGIN INIT INFO
# Provides: regenerate_ssh_host_keys
# Required-Start:
# Required-Stop:
# Default-Start: 2
# Default-Stop:
# Short-Description: Regenerate ssh host keys
# Description:
### END INIT INFO
. /lib/lsb/init-functions
set -e
case "$1" in
start)
log_daemon_msg "Regenerating ssh host keys (in background)"
modprobe -q bcm2708-rng && dd if=/dev/hwrng of=/dev/urandom count=1 bs=4096 2>/dev/null
nohup sh -c "yes | ssh-keygen -q -N '' -t dsa -f /etc/ssh/ssh_host_dsa_key && \
yes | ssh-keygen -q -N '' -t rsa -f /etc/ssh/ssh_host_rsa_key && \
yes | ssh-keygen -q -N '' -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key && \
yes | ssh-keygen -q -N '' -t ed25519 -f /etc/ssh/ssh_host_ed25519_key && \
systemctl enable ssh && sync && \
rm /etc/init.d/regenerate_ssh_host_keys && \
update-rc.d regenerate_ssh_host_keys remove && \
printf '\nfinished\n' && systemctl start ssh" > /var/log/regen_ssh_keys.log 2>&1 &
log_end_msg $?
;;
*)
echo "Usage: $0 start" >&2
exit 3
;;
esac
Code: Select all
strace -xe trace=file,read,write,close ssh-keygen -f /tmp/ssh_host_rsa_key -N '' -t rsa
Code: Select all
...
open("/dev/urandom", O_RDONLY|O_NOCTTY|O_NONBLOCK) = 3
read(3, "\xfc\x60\x50\x8b\x46\x12\xd2\x3b\x62\xc4\x34\x8f\x21\x1d\xef\xe4\x15\xa7\xda\x05\x4f\x07\xc6\x8e\xd7\x84\x24\x54\xc5\xf9\x90\xb2", 32) = 32
close(3) = 0
...