Skip to content

Instantly share code, notes, and snippets.

@og-shawn-crigger
Created June 20, 2013 15:16
Show Gist options
  • Save og-shawn-crigger/5823652 to your computer and use it in GitHub Desktop.
Save og-shawn-crigger/5823652 to your computer and use it in GitHub Desktop.
Copy your ssh public key to a server from a machine that doesn't have ssh-copy-id If you use Mac OS X or some other *nix variant that doesn't come with ssh-copy-id, this one-liner will allow you to add your public key to a remote machine so you can subsequently ssh to that machine without a password.
cat ~/.ssh/id_rsa.pub | ssh user@machine "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"
@og-shawn-crigger
Copy link
Author

might have to remove the mkdir as most servers already have a .ssh directory

@jcanfield
Copy link

So that is a good one.. this is what I do..

#!/bin/bash
# /usr/local/sbin/copykeys symlinked from ~/
# USAGE: copykeys username@hostname.com

echo "Copying local SSH Key to $1..."
cat ~/.ssh/id_rsa.pub | ssh $1 "cat - >> .ssh/authorized_keys"
echo "Your Public SSH Key was copied to $1."

exit

@jcanfield
Copy link

Shawn, what do you think of that? I try to make all of my Bash and Ruby cli scripts somewhat interactive.

@og-shawn-crigger
Copy link
Author

I like that one much better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment