Skip to content

Instantly share code, notes, and snippets.

@connoro7
Last active May 24, 2020 19:56
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 connoro7/8cba0600c2a6a8704ea02346c4178482 to your computer and use it in GitHub Desktop.
Save connoro7/8cba0600c2a6a8704ea02346c4178482 to your computer and use it in GitHub Desktop.
Bash script to export all SSH keys (public and private) to external folder for backup on a cold storage drive.
#!/bin/bash
# Edit EXPORT_FOLDER to change the export location
EXPORT_FOLDER=~/ssh_export
# Append (or remove) any additional key locations you may have to the KEYS array.
KEYS=(~/.gnupg ~/.pki/nssdb ~/.gnome2/keyrings ~/.ssh /usr/local/apache2/conf/ssl.crt/server.crt /usr/local/apache2/conf/ssl.key/server.key /etc/ssh /etc/ssl/private /etc/cups/ssl)
#
echo -e "SSH Keys being sent to: \033[44;97m$EXPORT_FOLDER\033[0m"
for FILE in "${KEYS[@]}"
do
# for use with OSX
sudo rsync -a $FILE $EXPORT_FOLDER && echo -e "\033[0;32mCopied $FILE\033[0m" || echo -e "\033[0;31mFailed to export $FILE\033[0m"
# for use with Linux
# sudo cp --parents $FILE $EXPORT_FOLDER && echo -e "\033[0;32mCopied $FILE\033[0m" || echo -e "\033[0;31mFailed to export $FILE\033[0m"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment