Resetting OpenSSH Host Keys (the easy method)

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.

YouTube player

You can find the systemd unit file I used in the video here.

Commands used in this video

  1. Copy the systemd unit file, and name it as regenerate_ssh_host_keys.service
  2. Set ownership of the unit file to root: sudo chown root:root regenerate_ssh_host_keys.service
  3. Move the unit file to a more appropriate place: sudo mv regenerate_ssh_host_keys.service /etc/systemd/system
  4. Reload systemd: sudo systemctl daemon-reload
  5. Enable the unit (warning, at next boot your host keys will reset): sudo systemctl enable regenerate_ssh_host_keys.service

Brand-New Course!

Check out Jay’s new course on Ansible and start automating today!

Discount Vouchers


Receive 5% off an LPI exam voucher!

Exclusive Member Features

Support the channel and receive exclusive perks!