Skip to content

Instantly share code, notes, and snippets.

@yevrah
Created September 2, 2014 22:11
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 yevrah/45e4f102169b4c4fcb4f to your computer and use it in GitHub Desktop.
Save yevrah/45e4f102169b4c4fcb4f to your computer and use it in GitHub Desktop.
Copy SSH Keys To Remote Server
#!/usr/bin/env bash
# Usage
# copy_ssh_keys.sh user@host
#
# Notes
# Makes sure to generate your ssh keys before running, if
# you havent done so just uncomment the line below
# ssh-keygen -t rsa
echo -e "\n>>> Creating remote .ssh folder"
ssh -t $1 "mkdir ~/.ssh"
echo -e "\n>>>Updating .ssh folder permissions"
ssh -t $1 "chmod 700 ~/.ssh"
echo -e "\n>>>Copying Auth Keys"
cat ~/.ssh/id_rsa.pub | ssh $1 "cat >> ~/.ssh/authorized_keys"
echo -e "\n>>>Updating auth keys permissions"
ssh -t $1 "chmod 600 ~/.ssh/authorized_keys"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment