1999-10-27 03:42:43 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
1999-10-28 04:03:14 +00:00
|
|
|
# Init file for OpenSSH server daemon
|
1999-10-27 03:42:43 +00:00
|
|
|
#
|
|
|
|
# chkconfig: 2345 55 25
|
|
|
|
# description: OpenSSH server daemon
|
|
|
|
#
|
1999-10-28 23:18:29 +00:00
|
|
|
# processname: sshd
|
|
|
|
# config: /etc/ssh/ssh_host_key
|
|
|
|
# config: /etc/ssh/ssh_host_key.pub
|
|
|
|
# config: /etc/ssh/ssh_random_seed
|
|
|
|
# config: /etc/ssh/sshd_config
|
|
|
|
# pidfile: /var/run/sshd.pid
|
1999-10-27 03:42:43 +00:00
|
|
|
|
|
|
|
# source function library
|
|
|
|
. /etc/rc.d/init.d/functions
|
|
|
|
|
2001-04-27 00:46:17 +00:00
|
|
|
[ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd
|
|
|
|
|
1999-10-27 03:42:43 +00:00
|
|
|
RETVAL=0
|
|
|
|
|
2000-08-08 06:53:28 +00:00
|
|
|
# Some functions to make the below more readable
|
|
|
|
KEYGEN=/usr/bin/ssh-keygen
|
2000-11-13 11:57:25 +00:00
|
|
|
RSA1_KEY=/etc/ssh/ssh_host_key
|
|
|
|
RSA_KEY=/etc/ssh/ssh_host_rsa_key
|
2000-08-08 06:53:28 +00:00
|
|
|
DSA_KEY=/etc/ssh/ssh_host_dsa_key
|
|
|
|
PID_FILE=/var/run/sshd.pid
|
2001-02-26 20:38:53 +00:00
|
|
|
my_success() {
|
|
|
|
local msg
|
|
|
|
if [ $# -gt 1 ]; then
|
|
|
|
msg="$2"
|
|
|
|
else
|
|
|
|
msg="done"
|
|
|
|
fi
|
|
|
|
case "`type -type success`" in
|
|
|
|
function)
|
|
|
|
success "$1"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo -n "${msg}"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
my_failure() {
|
|
|
|
local msg
|
|
|
|
if [ $# -gt 1 ]; then
|
|
|
|
msg="$2"
|
|
|
|
else
|
|
|
|
msg="FAILED"
|
|
|
|
fi
|
|
|
|
case "`type -type failure`" in
|
|
|
|
function)
|
|
|
|
failure "$1"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo -n "${msg}"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
2000-11-13 11:57:25 +00:00
|
|
|
do_rsa1_keygen() {
|
|
|
|
if ! test -f $RSA1_KEY ; then
|
|
|
|
echo -n "Generating SSH1 RSA host key: "
|
|
|
|
if $KEYGEN -q -t rsa1 -f $RSA1_KEY -C '' -N '' >&/dev/null; then
|
2001-02-26 20:38:53 +00:00
|
|
|
my_success "RSA1 key generation"
|
2000-11-13 11:57:25 +00:00
|
|
|
echo
|
|
|
|
else
|
2001-02-26 20:38:53 +00:00
|
|
|
my_failure "RSA1 key generation"
|
2000-11-13 11:57:25 +00:00
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
2000-08-08 06:53:28 +00:00
|
|
|
do_rsa_keygen() {
|
2000-11-13 11:57:25 +00:00
|
|
|
if ! test -f $RSA_KEY ; then
|
|
|
|
echo -n "Generating SSH2 RSA host key: "
|
|
|
|
if $KEYGEN -q -t rsa -f $RSA_KEY -C '' -N '' >&/dev/null; then
|
2001-02-26 20:38:53 +00:00
|
|
|
my_success "RSA key generation"
|
2000-08-08 06:53:28 +00:00
|
|
|
echo
|
|
|
|
else
|
2001-02-26 20:38:53 +00:00
|
|
|
my_failure "RSA key generation"
|
2000-08-08 06:53:28 +00:00
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
fi
|
1999-11-13 12:56:35 +00:00
|
|
|
fi
|
2000-08-08 06:53:28 +00:00
|
|
|
}
|
|
|
|
do_dsa_keygen() {
|
|
|
|
if ! test -f $DSA_KEY ; then
|
2000-11-13 11:57:25 +00:00
|
|
|
echo -n "Generating SSH2 DSA host key: "
|
|
|
|
if $KEYGEN -q -t dsa -f $DSA_KEY -C '' -N '' >&/dev/null; then
|
2001-02-26 20:38:53 +00:00
|
|
|
my_success "DSA key generation"
|
2000-08-08 06:53:28 +00:00
|
|
|
echo
|
|
|
|
else
|
2001-02-26 20:38:53 +00:00
|
|
|
my_failure "DSA key generation"
|
2000-08-08 06:53:28 +00:00
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
fi
|
1999-11-13 12:56:35 +00:00
|
|
|
fi
|
2000-08-08 06:53:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
start)
|
|
|
|
# Create keys if necessary
|
2000-11-13 11:57:25 +00:00
|
|
|
do_rsa1_keygen;
|
2000-08-08 06:53:28 +00:00
|
|
|
do_rsa_keygen;
|
|
|
|
do_dsa_keygen;
|
|
|
|
|
|
|
|
echo -n "Starting sshd: "
|
|
|
|
if [ ! -f $PID_FILE ] ; then
|
2001-04-27 00:46:17 +00:00
|
|
|
sshd $OPTIONS
|
2000-08-08 06:53:28 +00:00
|
|
|
RETVAL=$?
|
2000-09-03 08:14:58 +00:00
|
|
|
if [ "$RETVAL" = "0" ] ; then
|
2001-02-26 20:38:53 +00:00
|
|
|
my_success "sshd startup" "sshd"
|
2000-09-03 08:14:58 +00:00
|
|
|
touch /var/lock/subsys/sshd
|
|
|
|
else
|
2001-02-26 20:38:53 +00:00
|
|
|
my_failure "sshd startup" ""
|
2000-09-03 08:14:58 +00:00
|
|
|
fi
|
2000-08-08 06:53:28 +00:00
|
|
|
fi
|
|
|
|
echo
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
echo -n "Shutting down sshd: "
|
|
|
|
if [ -f $PID_FILE ] ; then
|
|
|
|
killproc sshd
|
2000-11-07 16:41:41 +00:00
|
|
|
RETVAL=$?
|
2000-08-08 06:53:28 +00:00
|
|
|
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sshd
|
|
|
|
fi
|
|
|
|
echo
|
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
$0 stop
|
|
|
|
$0 start
|
|
|
|
RETVAL=$?
|
|
|
|
;;
|
2000-10-16 01:25:17 +00:00
|
|
|
condrestart)
|
|
|
|
if [ -f /var/lock/subsys/sshd ] ; then
|
|
|
|
$0 stop
|
|
|
|
$0 start
|
|
|
|
RETVAL=$?
|
|
|
|
fi
|
|
|
|
;;
|
2000-08-08 06:53:28 +00:00
|
|
|
status)
|
|
|
|
status sshd
|
|
|
|
RETVAL=$?
|
|
|
|
;;
|
|
|
|
*)
|
2000-10-16 01:25:17 +00:00
|
|
|
echo "Usage: sshd {start|stop|restart|status|condrestart}"
|
2000-08-08 06:53:28 +00:00
|
|
|
exit 1
|
|
|
|
;;
|
1999-10-27 03:42:43 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
exit $RETVAL
|