Skip to content

Instantly share code, notes, and snippets.

@robacarp
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robacarp/10193438 to your computer and use it in GitHub Desktop.
Save robacarp/10193438 to your computer and use it in GitHub Desktop.
Bash script to rekey a server (untested)
#!/bin/bash
set -e
hostname
archive_dir="/etc/ssh/compromised_keys/$(date +%F)"
mkdir -p $archive_dir
mv /etc/ssh/ssh*_key $archive_dir
mv /etc/ssh/ssh*_key.pub $archive_dir
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa >> $archive_dir/regen_log
ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa >> $archive_dir/regen_log
ssh-keygen -f /etc/ssh/ssh_host_ecdsa_key -N '' -t ecdsa >> $archive_dir/regen_log
ssh-keygen -lf /etc/ssh/ssh_host_rsa_key
ssh-keygen -lf /etc/ssh/ssh_host_dsa_key
ssh-keygen -lf /etc/ssh/ssh_host_ecdsa_key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment