]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core.git/commitdiff
rootfs-postcommands.bbclass: avoid checking hard-coded openssh hostkey
authorMing Liu <liu.ming50@gmail.com>
Sat, 17 Jan 2026 12:05:23 +0000 (13:05 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 22 Jan 2026 14:21:52 +0000 (14:21 +0000)
The openssh host keys are configurable in openssh recipe, dont check
hard-coded path ${IMAGE_ROOTFS}/etc/ssh/ssh_host_rsa_key. Instead, try
to figure out the first host key in sshd_config, if there is no host
keys set in sshd_config, then check the first host key presenting in
${IMAGE_ROOTFS}/etc/ssh.

Signed-off-by: Ming Liu <liu.ming50@gmail.com>
Signed-off-by: Antonin Godard <antonin.godard@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes-recipe/rootfs-postcommands.bbclass

index f0c7ee658d42c693bb6bf1e262e96501a4b7fbf2..02cb97aec76697596552526f1b9162fcf99ce170 100644 (file)
@@ -214,7 +214,11 @@ read_only_rootfs_hook () {
        # If stateless-rootfs is enabled this is always done as we don't want to save keys then
        if ${@ 'true' if not bb.utils.contains('IMAGE_FEATURES', 'overlayfs-etc', True, False, d) or bb.utils.contains('IMAGE_FEATURES', 'stateless-rootfs', True, False, d) else 'false'}; then
                if [ -d ${IMAGE_ROOTFS}/etc/ssh ]; then
-                       if [ -e ${IMAGE_ROOTFS}/etc/ssh/ssh_host_rsa_key ]; then
+                       ssh_host_key_checkpath=$(sed -n 's/^[ \t]*HostKey[ \t]\+\(.*\)/\1/p' ${IMAGE_ROOTFS}/etc/ssh/sshd_config | head -1)
+                       if [ ! -e "$ssh_host_key_checkpath" ]; then
+                               ssh_host_key_checkpath=$(ls ${IMAGE_ROOTFS}/etc/ssh/ssh_host_*_key | cut -f1 | head -1)
+                       fi
+                       if [ -e "$ssh_host_key_checkpath" ]; then
                                echo "SYSCONFDIR=\${SYSCONFDIR:-/etc/ssh}" >> ${IMAGE_ROOTFS}/etc/default/ssh
                                echo "SSHD_OPTS=" >> ${IMAGE_ROOTFS}/etc/default/ssh
                        else