Instantly share code, notes, and snippets.

What would you like to do?
Move local SSH keys to production machine
# sends your local dev machines keys to the production machine for easy deployment + ssh
if [[ ! -e ~/.ssh/ ]]; then
echo "Local keys do not exist, creating them..."
ssh-keygen -t rsa
echo "username"
read username
echo "domain"
read domain
if [[ ! -e ~/.ssh/ ]]; then
echo "You do not have a SSH key generated locally"
exit 1
scp ~/.ssh/ "$username"@"$domain":~/tmp_key
ssh "$username"@"$domain" 'if [[ ! -e ~/.ssh/ ]]; then mkdir -m 700 ~/.ssh; fi; if [[ ! -e ~/.ssh/authorized_keys ]]; then touch ~/.ssh/authorized_keys; fi; chmod 600 ~/.ssh/authorized_keys; cat ~/tmp_key >> ~/.ssh/authorized_keys; rm ~/tmp_key'
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment