Regenerate ssh host keys on boot on Ubuntu

As a part of preparing your linux VM to become template VM, you will delete all ssh host keys inside /etc/ssh/ folder:

rm -f /etc/ssh/*key*

This is not a problem with CentOS, which does check on every boot if host keys exist, and recreate them as neccessary.

But Ubuntu being smart ass, does not regenerate keys on boot, so after you delete all existing ssh host keys, be sure to add folowing to your /etc/rc.local file:

#Generate new host keys, if old ones are deleted"
test -f /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-server

Be sure to add these lines before the “exit 0” line 😉

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: