Skip to content

Instantly share code, notes, and snippets.

@gabrielfalcao
Created June 29, 2010 13:25
Show Gist options
  • Save gabrielfalcao/457204 to your computer and use it in GitHub Desktop.
Save gabrielfalcao/457204 to your computer and use it in GitHub Desktop.
#!/bin/sh
# ssh-copy-id for mac os x
KEY="$HOME/.ssh/id_rsa.pub"
if [ ! -f $KEY ];then
echo "private key not found at $KEY"
echo "* please create it with "ssh-keygen -t dsa" *"
echo "* to login to the remote host without a password, don't give the key you create with ssh-keygen a password! *"
exit
fi
if [ -z $1 ];then
echo "Please specify [email protected] as the first switch to this script"
exit
fi
echo "Putting your key on $1... "
KEYCODE=`cat $KEY`
cat $KEY | ssh $1 "cat - >> ~/.authorized_keys ; mkdir -p ~/.ssh ; mv ~/.authorized_keys ~/.ssh/authorized_keys"
echo "done!"
@Et7f3
Copy link

Et7f3 commented May 7, 2022

new Mac OS has ssh-copy-id builtin that handle more key type and more ssh server like dropbear. You should run shellcheck on you code because it has quoting issue. You should try to use more recent algorithm like rsa or even better ed25519.

@gabrielfalcao
Copy link
Author

gabrielfalcao commented May 8, 2022

Hey @Et7f3 it befuddles me to wonder why - or even how - you found this piece of code I wrote 12 years ago. But I learned a lot from your feedback. Thank you!

@Et7f3
Copy link

Et7f3 commented May 8, 2022

I searched upstream of mac os ssh copy id to fix something. Apparently it is bsd repo. And I found your gists with google.

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