#!/bin/sh # sshd # Source functions library source /etc/rc.d/init.d/functions source /etc/sysconfig/network/network-parameters log_script_name "$0 $*" SSHD="/usr/sbin/sshd -4" # Check if SSH server is desired if [ "x${SSH_SERVER_ENA}" != "xyes" -a "x${SSH_SERVER_ENA}" != "xYes" -a "x${SSH_SERVER_ENA}" != "xYES" ]; then exit ${EXIT_CODE_SUCCESS} fi gen_keys() { if [ ! -e /etc/ssh/ssh_host_key ] ; then echo "Generating Hostkey..." /usr/bin/ssh-keygen -t rsa1 -b 1024 -f /etc/ssh/ssh_host_key -N '' fi if [ ! -e /etc/ssh/ssh_host_dsa_key ] ; then echo "Generating DSA-Hostkey..." /usr/bin/ssh-keygen -d -f /etc/ssh/ssh_host_dsa_key -N '' fi if [ ! -e /etc/ssh/ssh_host_rsa_key ] ; then echo "Generating RSA-Hostkey..." /usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' fi } sshd_start() { # Checking configuration if [ ! -e /etc/ssh/sshd_config ] ; then echo "You need an /etc/ssh/sshd_config file to run sshd" echo "There is a sample file in /usr/share/doc/openssh" exit ${EXIT_CODE_FAILURE} fi gen_keys if [ $? -ne 0 ]; then exit ${EXIT_CODE_FAILURE} else loadproc ${SSHD} fi } # See how we were called case "$1" in start) cmd_run_log_box_warn "Starting sshd" sshd_start ;; stop) cmd_run_log_box_warn "Stopping sshd" killproc sshd ;; reload) reloadproc sshd ;; restart) $0 stop sleep 1 $0 start ;; status) statusproc sshd ;; *) echo "Usage: $0 {reload|restart|start|status|stop}" exit ${EXIT_CODE_FAILURE} ;; esac exit $?