If the rootfs is read-only and the ssh keys are not available at system start-up, the init script will generate ssh keys into /etc/ssh, thus causing a 'read-only file system' error. In order for Yocto based image to work correctly for read-only rootfs, we use the following logic for openssh. If the rootfs is read-only and there are pre-generated keys under /etc/ssh, we use the pre-generated keys. Note the pre-generated keys are mainly for debugging or development purpose. If the rootfs is read-only and there are no pre-generated keys under /etc/ssh, we use /var/run/ssh as the location for ssh keys. That is, at system boot-up, the generated ssh keys will put into /var/run/ssh. [YOCTO #4887] (From OE-Core rev: 2ed44745024f04aa4e00ddba3009153c6b47c8e9) Signed-off-by: Chen Qi <Qi.Chen@windriver.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2.3 KiB
#! /bin/sh set -e
/etc/init.d/ssh: start and stop the OpenBSD "secure shell" daemon
test -x /usr/sbin/sshd || exit 0 ( /usr/sbin/sshd -? 2>&1 | grep -q OpenSSH ) 2>/dev/null || exit 0
/etc/default/ssh may set SYSCONFDIR and SSHD_OPTS
if test -f /etc/default/ssh; then . /etc/default/ssh fi
[ -z "$SYSCONFDIR" ] && SYSCONFDIR=/etc/ssh mkdir -p $SYSCONFDIR
HOST_KEY_RSA=$SYSCONFDIR/ssh_host_rsa_key HOST_KEY_DSA=$SYSCONFDIR/ssh_host_dsa_key HOST_KEY_ECDSA=$SYSCONFDIR/ssh_host_ecdsa_key
check_for_no_start() { # forget it if we're trying to start, and /etc/ssh/sshd_not_to_be_run exists if [ -e $SYSCONFDIR/sshd_not_to_be_run ]; then echo "OpenBSD Secure Shell server not in use ($SYSCONFDIR/sshd_not_to_be_run)" exit 0 fi }
check_privsep_dir() { # Create the PrivSep empty dir if necessary if [ ! -d /var/run/sshd ]; then mkdir /var/run/sshd chmod 0755 /var/run/sshd fi }
check_config() { /usr/sbin/sshd -t || exit 1 }
check_keys() { # create keys if necessary if [ ! -f $HOST_KEY_RSA ]; then echo " generating ssh RSA key..." ssh-keygen -q -f $HOST_KEY_RSA -N '' -t rsa fi if [ ! -f $HOST_KEY_ECDSA ]; then echo " generating ssh ECDSA key..." ssh-keygen -q -f $HOST_KEY_ECDSA -N '' -t ecdsa fi if [ ! -f /etc/ssh/ssh_host_dsa_key ]; then echo " generating ssh DSA key..." ssh-keygen -q -f $HOST_KEY_DSA -N '' -t dsa fi }
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
case "$1" in start) check_for_no_start echo "Starting OpenBSD Secure Shell server: sshd" check_keys check_privsep_dir start-stop-daemon -S -x /usr/sbin/sshd -- $SSHD_OPTS echo "done." ;; stop) echo -n "Stopping OpenBSD Secure Shell server: sshd" start-stop-daemon -K -x /usr/sbin/sshd echo "." ;;
reload|force-reload) check_for_no_start check_keys check_config echo -n "Reloading OpenBSD Secure Shell server's configuration" start-stop-daemon -K -s 1 -x /usr/sbin/sshd echo "." ;;
restart) check_keys check_config echo -n "Restarting OpenBSD Secure Shell server: sshd" start-stop-daemon -K --oknodo -x /usr/sbin/sshd check_for_no_start check_privsep_dir sleep 2 start-stop-daemon -S -x /usr/sbin/sshd -- $SSHD_OPTS echo "." ;;
*) echo "Usage: /etc/init.d/ssh {start|stop|reload|force-reload|restart}" exit 1 esac
exit 0