sshd.init 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/sh
  2. #PKG openssh-server
  3. #INIT 50
  4. . /etc/rc.conf
  5. case $1 in
  6. autostop) ;;
  7. autostart)
  8. test x"${openssh:-NO}" = x"NO" && exit 0
  9. grep "^dropbear" /etc/rc.conf >/dev/null 2>&1 || dropbear=NO
  10. if [[ $openssh = AUTO && $dropbear != NO ]]; then
  11. echo openssh not starting: set to AUTO and dropbear is enabled
  12. exit 0
  13. fi
  14. exec sh $0 start
  15. ;;
  16. start)
  17. if [[ ! -s /etc/ssh/ssh_host_rsa_key ]]; then
  18. mkdir -p /etc/ssh
  19. if [[ ! -x /usr/bin/ssh-keygen ]]; then
  20. echo "openssh not starting: SSH private key missing"
  21. exit 0
  22. fi
  23. echo "openssh: generating SSH private key (RSA)"
  24. /usr/bin/ssh-keygen -N '' -t rsa -f /etc/ssh/ssh_host_rsa_key
  25. rv=$?
  26. echo openssh: key generation exited with code $rv
  27. [[ $rv = 0 && -s /etc/ssh/ssh_host_rsa_key ]] || exit 1
  28. fi
  29. mkdir -p /var/run/sshd
  30. mkdir -p /var/empty
  31. touch /var/log/btmp && chmod 600 /var/log/btmp
  32. /usr/sbin/sshd
  33. ;;
  34. stop)
  35. if [ -e /var/run/sshd.pid ]; then
  36. kill $(cat /var/run/sshd.pid)
  37. fi
  38. ;;
  39. restart)
  40. sh $0 stop
  41. sh $0 start
  42. ;;
  43. *)
  44. echo "Usage: $0 {start | stop | restart}"
  45. exit 1
  46. ;;
  47. esac
  48. exit $?