summaryrefslogtreecommitdiff
path: root/mksshauth
blob: 8666702b7175bcab4050795922a74880ea407eb5 (plain)
  1. #!/bin/sh
  2. #
  3. # /usr/local/bin/mksshauth
  4. # Copyright 2000-2001 Juri Jensen <juri@xenux.dk>
  5. # Copyright 2002 Juri Jensen <juri@xenux.dk> & Jonas Smedegaard <dr@jones.dk>
  6. #
  7. # $Id: mksshauth,v 1.4 2002-12-03 17:29:39 jonas Exp $
  8. #
  9. # Setup local and remote SSH for non-interactive authorization
  10. #
  11. set -e
  12. prg=`basename $0`
  13. if [ $# \< 2 ]; then
  14. echo "ERROR: Wrong arguments! (Use '$prg --help' for help)"
  15. exit 1
  16. fi
  17. keytype=$1
  18. host=$2
  19. shift
  20. shift
  21. options=$@
  22. case "$keytype" in
  23. --help|-h)
  24. echo "$prg: Setup local and remote SSH for non-interactive authorization."
  25. echo
  26. echo "Usage: $prg keytype [user@]host [options]"
  27. echo
  28. echo "Options:"
  29. echo " keytype: SSH key type, either rsa1, rsa, dsa, 1 or 2."
  30. echo " rsa1 is for SSHv1, rsa and dsa is for SSHv2. 1 and 2 are"
  31. echo " aliases for rsa1 and dsa. dsa (or 2) is recommended."
  32. echo " user: User id on remote host. Default is same as local user."
  33. echo " host: Hostname of remote host."
  34. echo " options: Options to prepend the authorization key (read 'man sshd')."
  35. exit 0
  36. ;;
  37. 1|rsa1)
  38. keytype=rsa1
  39. id_file=identity.pub
  40. auth_file=authorized_keys
  41. ;;
  42. 2|dsa)
  43. keytype=dsa
  44. id_file=id_dsa.pub
  45. auth_file=authorized_keys2
  46. ;;
  47. rsa)
  48. keytype=rsa
  49. id_file=id_rsa.pub
  50. auth_file=authorized_keys2
  51. ;;
  52. *)
  53. echo "ERROR: Wrong keytype! (Use '$prg --help' for help)"
  54. exit 1
  55. ;;
  56. esac
  57. if [ -n "$options" ]; then
  58. options="$options "
  59. fi
  60. [ -f ~/.ssh/$id_file ] || ssh-keygen -t $keytype
  61. ssh $host "mkdir -p ~/.ssh && echo '$options'`cat ~/.ssh/$id_file` >> ~/.ssh/$auth_file"