From 2ed44745024f04aa4e00ddba3009153c6b47c8e9 Mon Sep 17 00:00:00 2001 From: Chen Qi Date: Mon, 29 Jul 2013 10:11:07 +0800 Subject: openssh: fix for read-only rootfs 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] Signed-off-by: Chen Qi Signed-off-by: Saul Wold --- meta/classes/image.bbclass | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'meta/classes/image.bbclass') diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass index 494664627d..116bd226ea 100644 --- a/meta/classes/image.bbclass +++ b/meta/classes/image.bbclass @@ -262,6 +262,18 @@ read_only_rootfs_hook () { if [ -x ${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh ]; then ${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh fi + # If we're using openssh and the /etc/ssh directory has no pre-generated keys, + # we should configure openssh to use the configuration file /etc/ssh/sshd_config_readonly + # and the keys under /var/run/ssh. + if [ -d ${IMAGE_ROOTFS}/etc/ssh ]; then + if [ -e ${IMAGE_ROOTFS}/etc/ssh/ssh_host_rsa_key ]; then + echo "SYSCONFDIR=/etc/ssh" >> ${IMAGE_ROOTFS}/etc/default/ssh + echo "SSHD_OPTS=" >> ${IMAGE_ROOTFS}/etc/default/ssh + else + echo "SYSCONFDIR=/var/run/ssh" >> ${IMAGE_ROOTFS}/etc/default/ssh + echo "SSHD_OPTS='-f /etc/ssh/sshd_config_readonly'" >> ${IMAGE_ROOTFS}/etc/default/ssh + fi + fi fi } -- cgit 1.2.3-korg