a (614B) - raw


      1 #!/bin/sh
      2 # add an ssh key to the list of authorized keys
      3 
      4 echo "Paste the key to be added:"
      5 read key
      6 
      7 keyfile="$(mktemp)"
      8 echo "$key" > "$keyfile"
      9 
     10 # check for errors
     11 fingerprint="$(ssh-keygen -lf $keyfile)"
     12 if [ "$(echo "$fingerprint" | egrep -c '\((R|D)SA|ED25519\)')" -ne "1" ]; then
     13     echo "Error: $fingerprint"
     14     rm "$keyfile"
     15     exit 1
     16 fi
     17 
     18 mkdir -p .ssh && \
     19   echo -n "no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty " >> .ssh/authorized_keys && \
     20   cat "$keyfile" >> .ssh/authorized_keys
     21 
     22 rm "$keyfile"
     23 
     24 echo "Success! Added a key with the following fingerprint:"
     25 echo "$fingerprint"