Skip to content

Instantly share code, notes, and snippets.

@danielzen
Last active August 29, 2015 14:23
Show Gist options
  • Save danielzen/77cc4c6f60bbe5dc5f8a to your computer and use it in GitHub Desktop.
Save danielzen/77cc4c6f60bbe5dc5f8a to your computer and use it in GitHub Desktop.
ssh-copy-pub: simpler version of ssh-copy-id for copying employee/contractor public keys to remote server authorized_keys file
#!/bin/sh
display_usage() {
echo "This script must be run with at least 2 arguments."
echo "\nUsage:\n$0 pubKeyFile {ssh arguments}\n"
echo "Example: ssh-copy-pub john_rsa.pub [email protected]\n"
}
if [ $# -lt 2 ]
then
display_usage
exit 1
fi
pubKeyFile=$1; shift
cat $pubKeyFile | ssh "$@" 'cat >> .ssh/authorized_keys && echo "Key copied"'
@danielzen
Copy link
Author

Would like to mkdir -pm 700 .ssh && before the cat, but can't break the pipe....

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