You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.9 KiB

  1. #!/bin/sh
  2. RSA_FINGERPRINT="2048 SHA256:pBz+GiWLvh9uccTB50HTQOCXhD9FZPFin/tfGKAZApQ"
  3. RSA_KEYURL="https://gitlab.altinea.fr/altinea/install-scripts/raw/branch/master/ssh/altinea-rsa.pub"
  4. ED25519_FINGERPRINT="256 SHA256:TagxgsBxZhHFWiThYwe/hZSYjLBOHWBY2Ss0QsipmTw noc@altinea.fr"
  5. ED25519_KEYURL="https://gitlab.altinea.fr/altinea/install-scripts/raw/branch/master/ssh/altinea-ed25519.pub"
  6. RSAFALLBACK_FINGERPRINT="4096 SHA256:JnvBDtH6kqtno8GpjmZtppwqPGZYJJ0s/+1czIMdeiM"
  7. RSAFALLBACK_URL="https://gitlab.altinea.fr/altinea/install-scripts/raw/branch/master/ssh/support@altinea.fr.pub"
  8. if [ -x "$(which curl)" ] ; then
  9. COMMAND="curl -s "
  10. echo "Found curl, using it"
  11. elif [ -x "$(which wget)" ]; then
  12. COMMAND="wget -q -O - "
  13. echo "Found wget, fallback to that"
  14. else
  15. echo "Could not find curl or wget, please install one." >&2
  16. exit 3;
  17. fi
  18. if [ ! -d ~/.ssh ]; then
  19. mkdir ~/.ssh
  20. chmod 700 ~/.ssh
  21. fi
  22. if [ -w ~/.ssh/authorized_keys2 ]
  23. then
  24. echo "It seems you're still relying on authorized_keys2, this is (almost) deprecated."
  25. exit 1;
  26. else
  27. touch ~/.ssh/authorized_keys
  28. if [ $(ssh-keygen -E sha256 -lf ~/.ssh/authorized_keys 2>/dev/null |grep -c "$RSA_FINGERPRINT") -ne 0 ]
  29. then
  30. echo "Altinea RSA CA fingerprint found in authorized_keys file, not adding"
  31. else
  32. $COMMAND $RSA_KEYURL >> ~/.ssh/authorized_keys
  33. echo "Altinea RSA CA key deployed on account" `whoami`
  34. fi
  35. if [ $(ssh-keygen -E sha256 -lf ~/.ssh/authorized_keys 2>/dev/null |grep -c "$ED25519_FINGERPRINT") -ne 0 ]
  36. then
  37. echo "Altinea ED25519 CA fingerprint found in authorized_keys file, not adding"
  38. else
  39. $COMMAND $ED25519_KEYURL >> ~/.ssh/authorized_keys
  40. echo "Altinea ED25519 CA key deployed on account" `whoami`
  41. fi
  42. if [ $(ssh-keygen -E sha256 -lf ~/.ssh/authorized_keys 2>/dev/null |grep -c "$RSAFALLBACK_FINGERPRINT") -ne 0 ]
  43. then
  44. echo "Altinea fallback RSA fingerprint found in authorized_keys file, not adding"
  45. else
  46. $COMMAND $RSAFALLBACK_URL >> ~/.ssh/authorized_keys
  47. fi
  48. fi
  49. exit 0;