Skip to content

Instantly share code, notes, and snippets.

@pansapiens
Created November 3, 2017 03:20
Show Gist options
  • Save pansapiens/5c91190b8ded97c345b933d6a8b32a8f to your computer and use it in GitHub Desktop.
Save pansapiens/5c91190b8ded97c345b933d6a8b32a8f to your computer and use it in GitHub Desktop.
A quick script to add a public SSH key to the authorized_keys on another host
#!/bin/sh
set -e
if grep PRIVATE $1 >/dev/null; then
echo "Use the public key ($1.pub), not the private one !"
exit -1
fi
cat $1 | ssh $2 'umask 0077; mkdir -p .ssh; cat >> .ssh/authorized_keys && echo "Key $1 added to .ssh/authorized_keys on $2"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment