Skip to content

Instantly share code, notes, and snippets.

@hyfather
Forked from achamian/ssh-copy-id
Created June 9, 2011 11:11
Show Gist options
  • Save hyfather/1016537 to your computer and use it in GitHub Desktop.
Save hyfather/1016537 to your computer and use it in GitHub Desktop.
Copy public key to authorized_keys
#!/usr/bin/env sh
# Copy public key to authorized_keys of a remote machine
if [ -z $1 ];then
echo "Usage"
echo "ssh-copy-id hostname /path/to/public/key"
exit
fi
if [ -z $2 ]; then
KEYCODE=`ssh-add -L`
else
KEYCODE=`cat $2`
fi
ssh -q $1 "mkdir ~/.ssh 2>/dev/null; chmod 700 ~/.ssh; echo "$KEYCODE" >> ~/.ssh/authorized_keys; chmod 644 ~/.ssh/authorized_keys"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment