Skip to content

Instantly share code, notes, and snippets.

@danschultz
Created March 15, 2023 06:00
Show Gist options
  • Save danschultz/aafcf5f23a9ec08419b10d2b389ba90b to your computer and use it in GitHub Desktop.
Save danschultz/aafcf5f23a9ec08419b10d2b389ba90b to your computer and use it in GitHub Desktop.

Revisions

  1. danschultz created this gist Mar 15, 2023.
    14 changes: 14 additions & 0 deletions regenerate_ssh_host_keys.service
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    [Unit]
    Description=Regenerate SSH host keys
    Before=ssh.service
    ConditionFileIsExecutable=/usr/bin/ssh-keygen

    [Service]
    Type=oneshot
    ExecStartPre=-/bin/dd if=/dev/hwrng of=/dev/urandom count=1 bs=4096
    ExecStartPre=-/bin/sh -c "/bin/rm -f -v /etc/ssh/ssh_host_*_key*"
    ExecStart=/usr/bin/ssh-keygen -A -v
    ExecStartPost=/bin/systemctl disable regenerate_ssh_host_keys

    [Install]
    WantedBy=multi-user.target