Created
December 26, 2013 21:28
Revisions
-
jacquarg created this gist
Dec 26, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ #!/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