Last active
May 24, 2020 19:56
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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