Skip to content

Instantly share code, notes, and snippets.

@jcanfield
Last active December 11, 2015 01:18
Show Gist options
  • Save jcanfield/4522006 to your computer and use it in GitHub Desktop.
Save jcanfield/4522006 to your computer and use it in GitHub Desktop.
Copy SSH Key to Remote Server
# Copy SSH Keys to Remote Server (for password-less access)
#
# More information copying SSH Keys to remote servers can be found at, https://help.ubuntu.com/community/SSH/OpenSSH/Keys.
# Method One is to create a simple script.
# I typically create the script in my ~/.bin and symbolically it to my /usr/local/sbin.
# $ touch ~/.bin/copykeys.sh
# $ chmod +x ~/.bin/copykeys.sh
# $ nano ~/.bin/copykeys.sh
# $ sudo ln -s /home/yourusername/.bin/copykeys.sh /usr/local/sbin/copy-ssh-key
#!/bin/bash
echo "Copying local SSH Key to $1..."
echo "Example Usage: copy-ssh-key username@hostname.com"
cat ~/.ssh/id_rsa.pub | ssh $1 "cat - >> .ssh/authorized_keys"
echo "Your Public SSH Key was copied to $1."
exit
# Second Method is use the Copy Keys script available via the Repositories (Debian/Ubuntu0
ssh-copy-id <username>@<host>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment