sshd 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/sh
  2. ########################################################################
  3. # Begin sshd
  4. #
  5. # Description : Start sshd daemon
  6. #
  7. # Author : Bruce Dubbs - bdubbs@linuxfromscratch.org
  8. #
  9. # Version : LFS 7.0
  10. #
  11. ########################################################################
  12. ### BEGIN INIT INFO
  13. # Provides: sshd
  14. # Required-Start: $network
  15. # Should-Start:
  16. # Required-Stop: sendsignals
  17. # Should-Stop:
  18. # Default-Start: 3 4 5
  19. # Default-Stop: 0 1 2 6
  20. # Short-Description: Starts sshd daemon.
  21. # Description: Starts sshd daemon.
  22. # X-LFS-Provided-By: LFS
  23. ### END INIT INFO
  24. . /lib/lsb/init-functions
  25. #$LastChangedBy: dj $
  26. #$Date: 2012-06-18 18:42:28 -0500 (Mon, 18 Jun 2012) $
  27. case "$1" in
  28. start)
  29. log_info_msg "Starting SSH Server..."
  30. if [ ! -f /etc/ssh/ssh_host_key ]; then
  31. /usr/bin/ssh-keygen -t rsa1 -N "" -f /etc/ssh/ssh_host_key
  32. fi
  33. if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
  34. /usr/bin/ssh-keygen -t rsa -N "" -f /etc/ssh/ssh_host_rsa_key
  35. fi
  36. if [ ! -f /etc/ssh/ssh_host_dsa_key ]; then
  37. /usr/bin/ssh-keygen -t dsa -N "" -f /etc/ssh/ssh_host_dsa_key
  38. fi
  39. if [ ! -f /etc/ssh/ssh_host_ecdsa_key ]; then
  40. /usr/bin/ssh-keygen -t ecdsa -N "" -f /etc/ssh/ssh_host_ecdsa_key
  41. fi
  42. if [ ! -f /etc/ssh/ssh_host_ed25519_key ]; then
  43. /usr/bin/ssh-keygen -t ed25519 -N "" -f /etc/ssh/ssh_host_ed25519_key
  44. fi
  45. start_daemon -f /usr/sbin/sshd
  46. evaluate_retval
  47. # Also prevent ssh from being killed by out of memory conditions
  48. sleep 1
  49. pid=`cat /run/sshd.pid 2>/dev/null`
  50. echo "-16" >/proc/${pid}/oom_score_adj
  51. ;;
  52. stop)
  53. log_info_msg "Stopping SSH Server..."
  54. killproc -p "/run/sshd.pid" /usr/sbin/sshd
  55. evaluate_retval
  56. ;;
  57. reload)
  58. log_info_msg "Reloading SSH Server..."
  59. pid=`cat /run/sshd.pid 2>/dev/null`
  60. if [ -n "${pid}" ]; then
  61. kill -HUP "${pid}"
  62. else
  63. (exit 1)
  64. fi
  65. evaluate_retval
  66. ;;
  67. restart)
  68. $0 stop
  69. sleep 1
  70. $0 start
  71. ;;
  72. status)
  73. statusproc /usr/sbin/sshd
  74. ;;
  75. *)
  76. echo "Usage: $0 {start|stop|reload|restart|status}"
  77. exit 1
  78. ;;
  79. esac
  80. # End sshd bootscript