When creating a deployment image or template for distributing Linux to devices or servers, it’s a good idea to make sure that you reset the host keys for SSH. In this video, I’ll show you an easy method I found for automating this.
You can find the systemd unit file I used in the video here.
Commands used in this video
- Copy the systemd unit file, and name it as
regenerate_ssh_host_keys.service
- Set ownership of the unit file to root:
sudo chown root:root regenerate_ssh_host_keys.service
- Move the unit file to a more appropriate place:
sudo mv regenerate_ssh_host_keys.service /etc/systemd/system
- Reload systemd:
sudo systemctl daemon-reload
- Enable the unit (warning, at next boot your host keys will reset):
sudo systemctl enable regenerate_ssh_host_keys.service