0

I believe this is an error. Every body is telling me that the ssh host key if deleted will be generated by reboot or restart sshd.

I have an ubuntu 9.10 machine (which run on Amazon EC2). This machine doesnot have sshd, just ssh. So, I delete all the key inside /etc/ssh with the thought that the key will be re-generated once I reboot the machine.

I'm not sure if it's correct, but if I reboot the machine, then the machine is no longer connectable via SSH.

Right after delete the keys, I try sudo service ssh reload. However, key is not generated. I have to regenerate it with ssh-keygen.

Would you guys please explain me why the key is not re-generated?

1 Answer 1

0

The reason your ssh host keys aren't re-generated at restart is because they are not supposed to. If you look inside your /etc/init.d/ssh you will see that there are no ssh-keygen commands present.

2
  • 1
    I've observed twice now within a week or so the SSH key changing after a reboot. I even confirmed that something (apparently an AWS 'init' script) removed the SSH keys and then re-generated them after I rebooted (NOT stopped+restarted) an EC2 instance. This answer on a similar question contains the command I ran to confirm that. Commented Aug 30, 2022 at 21:42
  • On Centos and RHEL derivatives, if you delete the hosts keys it will regenerate the keys... until some time ago. I used it a lot to generate images with no keys, and when images are instanciated, a new key specific to the instance is generated at Openssh first start. Now this is broken
    – Alex F
    Commented Sep 14, 2023 at 15:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .