summaryrefslogtreecommitdiff
path: root/mksshauth
blob: 83d6dd7952b680121c86ac03502179b8e6a592c2 (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.5 2003-03-24 12:08:47 jonas Exp $
  8. #
  9. # Setup local and remote SSH for non-interactive authorization
  10. #
  11. set -e
  12. prg=`basename $0`
  13. if [ $# \< 1 ]; then
  14. echo "ERROR: Wrong arguments! (Use '$prg --help' for help)"
  15. exit 1
  16. fi
  17. keytype=$1
  18. shift
  19. case "$keytype" in
  20. --help|-h)
  21. echo "$prg: Setup local and remote SSH for non-interactive authorization."
  22. echo
  23. echo "Usage: $prg keytype [user@]host [options]"
  24. echo
  25. echo "Options:"
  26. echo " keytype: SSH key type, either rsa1, rsa, dsa, 1 or 2."
  27. echo " rsa1 is for SSHv1, rsa and dsa is for SSHv2. 1 and 2 are"
  28. echo " aliases for rsa1 and dsa. dsa (or 2) is recommended."
  29. echo " user: User id on remote host. Default is same as local user."
  30. echo " host: Hostname of remote host."
  31. echo " options: Options to prepend the authorization key (read 'man sshd')."
  32. exit 0
  33. ;;
  34. 1|rsa1)
  35. keytype=rsa1
  36. id_file=identity.pub
  37. auth_file=authorized_keys
  38. ;;
  39. 2|dsa)
  40. keytype=dsa
  41. id_file=id_dsa.pub
  42. auth_file=authorized_keys2
  43. ;;
  44. rsa)
  45. keytype=rsa
  46. id_file=id_rsa.pub
  47. auth_file=authorized_keys2
  48. ;;
  49. *)
  50. echo "ERROR: Wrong keytype! (Use '$prg --help' for help)"
  51. exit 1
  52. ;;
  53. esac
  54. host=$1
  55. shift
  56. options=$@
  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"