Created
December 26, 2013 21:28
-
-
Save jacquarg/8138932 to your computer and use it in GitHub Desktop.
Append a new public key to authorized_key.
Useable with git-shell, (putted in git-shell-commands). Forked from http://planzero.org/blog/2012/10/24/hosting_an_admin-friendly_git_server_with_git-shell .
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Read in the SSH key | |
echo "Input the key to be added:" | |
read key | |
# Place the key in a temporary file (it's hard to get ssh-keygen | |
# to read from stdin; <<< works for bash, but is non-posix) | |
keyfile=$(tempfile) &&\ | |
echo "$key" > $keyfile | |
# Generate a fingerprint | |
fingerprint=$(ssh-keygen -lf $keyfile) | |
# Check for errors | |
if [ $(echo "$fingerprint" | egrep -c '(R|D)SA') -eq 0 ] | |
then | |
# Display the fingerprint error and clean up | |
echo "Error: $fingerprint" | |
rm $keyfile | |
exit 1 | |
fi | |
# Add the key to the authorised keys file and clean up | |
mkdir -p .ssh &&\ | |
echo -n "no-agent-forwarding,no-port-forwarding,no-X11-forwarding " >> .ssh/authorized_keys &&\ | |
cat $keyfile >> .ssh/authorized_keys | |
rm $keyfile | |
# Display the fingerprint for reference | |
echo "Success! Added a key with the following fingerprint:" | |
echo $fingerprint |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment