Skip to contentSkip to conversation

openssh: add variable for key path

PATCH Superseded Patrick Vogelaar 3 participants 6 messages Jan 2 – Feb 2

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 openssh: add variable for key path

This patch adds a variable for the key directory path. This is especially useful when working with a read-only file system where you want to specify the location e.g. on a r/w partition. To be consistent, the change was also done for the read write path.

For changing the path simply create a bbappend and override the variable.

---
 .../openssh/openssh_10.2p1.bb                    | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
meta/recipes-connectivity/openssh/openssh_10.2p1.bb +10 -6
index 866129573f..e319f4ac24 100644
@@ -99,6 +99,10 @@ CACHED_CONFIGUREVARS += "ac_cv_path_PATH_PASSWD_PROG=${bindir}/passwd"
 # We don't want to depend on libblockfile
 CACHED_CONFIGUREVARS += "ac_cv_header_maillock_h=no"
 
+# This allows overriding the key location in a bbappend
+RO_SSH_KEY_DIR ?= "/var/run/ssh"
+SSH_KEY_DIR ?= "/etc/ssh"
+
 do_configure:prepend () {
 	export LD="${CC}"
 	install -m 0600 ${UNPACKDIR}/sshd_config ${B}/
@@ -113,24 +117,24 @@ sshd_hostkey_setup() {
 	# Enable specific ssh host keys
 	sed -i '/HostKey/d' ${D}${sysconfdir}/ssh/sshd_config
 	if ${@bb.utils.contains('PACKAGECONFIG','hostkey-rsa','true','false',d)}; then
-		echo "HostKey /etc/ssh/ssh_host_rsa_key" >> ${D}${sysconfdir}/ssh/sshd_config
+		echo "HostKey ${SSH_KEY_DIR}/ssh_host_rsa_key" >> ${D}${sysconfdir}/ssh/sshd_config
 	fi
 	if ${@bb.utils.contains('PACKAGECONFIG','hostkey-ecdsa','true','false',d)}; then
-		echo "HostKey /etc/ssh/ssh_host_ecdsa_key" >> ${D}${sysconfdir}/ssh/sshd_config
+		echo "HostKey ${SSH_KEY_DIR}/ssh_host_ecdsa_key" >> ${D}${sysconfdir}/ssh/sshd_config
 	fi
 	if ${@bb.utils.contains('PACKAGECONFIG','hostkey-ed25519','true','false',d)}; then
-		echo "HostKey /etc/ssh/ssh_host_ed25519_key" >> ${D}${sysconfdir}/ssh/sshd_config
+		echo "HostKey ${SSH_KEY_DIR}/ssh_host_ed25519_key" >> ${D}${sysconfdir}/ssh/sshd_config
 	fi
 
 	sed -i '/HostKey/d' ${D}${sysconfdir}/ssh/sshd_config_readonly
 	if ${@bb.utils.contains('PACKAGECONFIG','hostkey-rsa','true','false',d)}; then
-		echo "HostKey /var/run/ssh/ssh_host_rsa_key" >> ${D}${sysconfdir}/ssh/sshd_config_readonly
+		echo "HostKey ${RO_SSH_KEY_DIR}/ssh_host_rsa_key" >> ${D}${sysconfdir}/ssh/sshd_config_readonly
 	fi
 	if ${@bb.utils.contains('PACKAGECONFIG','hostkey-ecdsa','true','false',d)}; then
-		echo "HostKey /var/run/ssh/ssh_host_ecdsa_key" >> ${D}${sysconfdir}/ssh/sshd_config_readonly
+		echo "HostKey ${RO_SSH_KEY_DIR}/ssh_host_ecdsa_key" >> ${D}${sysconfdir}/ssh/sshd_config_readonly
 	fi
 	if ${@bb.utils.contains('PACKAGECONFIG','hostkey-ed25519','true','false',d)}; then
-		echo "HostKey /var/run/ssh/ssh_host_ed25519_key" >> ${D}${sysconfdir}/ssh/sshd_config_readonly
+		echo "HostKey ${RO_SSH_KEY_DIR}/ssh_host_ed25519_key" >> ${D}${sysconfdir}/ssh/sshd_config_readonly
 	fi
 }
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 18 lines · Patrick Vogelaar via lists.openembedded.org

This patch adds a variable for the key directory path. This is especially useful when working with a read-only file system where you want to specify the location e.g. on a r/w partition. To be consistent, the change was also done for the read write path.

For changing the path simply create a bbappend and override the variable.

---
 .../openssh/openssh_10.2p1.bb                    | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
meta/recipes-connectivity/openssh/openssh_10.2p1.bb +0 -0
index 866129573f..e319f4ac24 100644

meta/recipes-connectivity/openssh/openssh_10.2p1.bb CACHED_CONFIGUREVARS += "ac_cv_path_PATH_PASSWD_PROG=${bindir}/passwd" · line 104

Quoted 6 lines
meta/recipes-connectivity/openssh/openssh_10.2p1.bb +3 -0
@@ -99,6 +99,10 @@ CACHED_CONFIGUREVARS += "ac_cv_path_PATH_PASSWD_PROG=${bindir}/passwd"
 # We don't want to depend on libblockfile
 CACHED_CONFIGUREVARS += "ac_cv_header_maillock_h=no"
 
+# This allows overriding the key location in a bbappend
+RO_SSH_KEY_DIR ?= "/var/run/ssh"
+SSH_KEY_DIR ?= "/etc/ssh"

The naming here is very easy to confuse, but I guess it's to match with the 'sshd_config' and 'sshd_config_readonly' filenames. I think we should be explicit in the RO case that we're talking about the read-only configuration though. And we'd prefer this as a suffix instead of a prefix.

Oh, and we should make it clear that this is specific to openssh, then these variables could be set from a config file instead of just a bbappend. And make it clear that it's for the host keys while we're at it.

Many 'and's there!

So, I suggest we use:

OPENSSH_HOST_KEY_DIR
OPENSSH_HOST_KEY_DIR_READONLY_CONFIG

Quoted 24 lines
meta/recipes-connectivity/openssh/openssh_10.2p1.bb +5 -4
+
 do_configure:prepend () {
 	export LD="${CC}"
 	install -m 0600 ${UNPACKDIR}/sshd_config ${B}/
@@ -113,24 +117,24 @@ sshd_hostkey_setup() {
 	# Enable specific ssh host keys
 	sed -i '/HostKey/d' ${D}${sysconfdir}/ssh/sshd_config
 	if ${@bb.utils.contains('PACKAGECONFIG','hostkey-rsa','true','false',d)}; then
-		echo "HostKey /etc/ssh/ssh_host_rsa_key" >> ${D}${sysconfdir}/ssh/sshd_config
+		echo "HostKey ${SSH_KEY_DIR}/ssh_host_rsa_key" >> ${D}${sysconfdir}/ssh/sshd_config
 	fi
 	if ${@bb.utils.contains('PACKAGECONFIG','hostkey-ecdsa','true','false',d)}; then
-		echo "HostKey /etc/ssh/ssh_host_ecdsa_key" >> ${D}${sysconfdir}/ssh/sshd_config
+		echo "HostKey ${SSH_KEY_DIR}/ssh_host_ecdsa_key" >> ${D}${sysconfdir}/ssh/sshd_config
 	fi
 	if ${@bb.utils.contains('PACKAGECONFIG','hostkey-ed25519','true','false',d)}; then
-		echo "HostKey /etc/ssh/ssh_host_ed25519_key" >> ${D}${sysconfdir}/ssh/sshd_config
+		echo "HostKey ${SSH_KEY_DIR}/ssh_host_ed25519_key" >> ${D}${sysconfdir}/ssh/sshd_config
 	fi
 
 	sed -i '/HostKey/d' ${D}${sysconfdir}/ssh/sshd_config_readonly
 	if ${@bb.utils.contains('PACKAGECONFIG','hostkey-rsa','true','false',d)}; then
-		echo "HostKey /var/run/ssh/ssh_host_rsa_key" >> ${D}${sysconfdir}/ssh/sshd_config_readonly
+		echo "HostKey ${RO_SSH_KEY_DIR}/ssh_host_rsa_key" >> ${D}${sysconfdir}/ssh/sshd_config_readonly

meta/recipes-connectivity/openssh/openssh_10.2p1.bb sshd_hostkey_setup() { · line 139

Quoted 10 lines
meta/recipes-connectivity/openssh/openssh_10.2p1.bb +2 -2
 	fi
 	if ${@bb.utils.contains('PACKAGECONFIG','hostkey-ecdsa','true','false',d)}; then
-		echo "HostKey /var/run/ssh/ssh_host_ecdsa_key" >> ${D}${sysconfdir}/ssh/sshd_config_readonly
+		echo "HostKey ${RO_SSH_KEY_DIR}/ssh_host_ecdsa_key" >> ${D}${sysconfdir}/ssh/sshd_config_readonly
 	fi
 	if ${@bb.utils.contains('PACKAGECONFIG','hostkey-ed25519','true','false',d)}; then
-		echo "HostKey /var/run/ssh/ssh_host_ed25519_key" >> ${D}${sysconfdir}/ssh/sshd_config_readonly
+		echo "HostKey ${RO_SSH_KEY_DIR}/ssh_host_ed25519_key" >> ${D}${sysconfdir}/ssh/sshd_config_readonly
 	fi
 }

Best regards,

Signature · 1 line
Paul Barker
#2 lore raw

PATCH v2 1/1 openssh: add variable for key path

In reply to Patrick Vogelaar

This patch adds a variable for the key directory path. This is especially useful when working with a read-only file system where you want to specify the location e.g. on a r/w partition. To be consistent, the change was also done for the read write path.

For changing the path simply create a bbappend and override the variable.

---
 .../openssh/openssh_10.2p1.bb                    | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
meta/recipes-connectivity/openssh/openssh_10.2p1.bb +10 -6
index 866129573f..d8ea487ae3 100644
@@ -99,6 +99,10 @@ CACHED_CONFIGUREVARS += "ac_cv_path_PATH_PASSWD_PROG=${bindir}/passwd"
 # We don't want to depend on libblockfile
 CACHED_CONFIGUREVARS += "ac_cv_header_maillock_h=no"
 
+# This allows overriding the key location
+OPENSSH_HOST_KEY_DIR_READONLY_CONFIG ?= "/var/run/ssh"
+OPENSSH_HOST_KEY_DIR ?= "/etc/ssh"
+
 do_configure:prepend () {
 	export LD="${CC}"
 	install -m 0600 ${UNPACKDIR}/sshd_config ${B}/
@@ -113,24 +117,24 @@ sshd_hostkey_setup() {
 	# Enable specific ssh host keys
 	sed -i '/HostKey/d' ${D}${sysconfdir}/ssh/sshd_config
 	if ${@bb.utils.contains('PACKAGECONFIG','hostkey-rsa','true','false',d)}; then
-		echo "HostKey /etc/ssh/ssh_host_rsa_key" >> ${D}${sysconfdir}/ssh/sshd_config
+		echo "HostKey ${OPENSSH_HOST_KEY_DIR}/ssh_host_rsa_key" >> ${D}${sysconfdir}/ssh/sshd_config
 	fi
 	if ${@bb.utils.contains('PACKAGECONFIG','hostkey-ecdsa','true','false',d)}; then
-		echo "HostKey /etc/ssh/ssh_host_ecdsa_key" >> ${D}${sysconfdir}/ssh/sshd_config
+		echo "HostKey ${OPENSSH_HOST_KEY_DIR}/ssh_host_ecdsa_key" >> ${D}${sysconfdir}/ssh/sshd_config
 	fi
 	if ${@bb.utils.contains('PACKAGECONFIG','hostkey-ed25519','true','false',d)}; then
-		echo "HostKey /etc/ssh/ssh_host_ed25519_key" >> ${D}${sysconfdir}/ssh/sshd_config
+		echo "HostKey ${OPENSSH_HOST_KEY_DIR}/ssh_host_ed25519_key" >> ${D}${sysconfdir}/ssh/sshd_config
 	fi
 
 	sed -i '/HostKey/d' ${D}${sysconfdir}/ssh/sshd_config_readonly
 	if ${@bb.utils.contains('PACKAGECONFIG','hostkey-rsa','true','false',d)}; then
-		echo "HostKey /var/run/ssh/ssh_host_rsa_key" >> ${D}${sysconfdir}/ssh/sshd_config_readonly
+		echo "HostKey ${OPENSSH_HOST_KEY_DIR_READONLY_CONFIG}/ssh_host_rsa_key" >> ${D}${sysconfdir}/ssh/sshd_config_readonly
 	fi
 	if ${@bb.utils.contains('PACKAGECONFIG','hostkey-ecdsa','true','false',d)}; then
-		echo "HostKey /var/run/ssh/ssh_host_ecdsa_key" >> ${D}${sysconfdir}/ssh/sshd_config_readonly
+		echo "HostKey ${OPENSSH_HOST_KEY_DIR_READONLY_CONFIG}/ssh_host_ecdsa_key" >> ${D}${sysconfdir}/ssh/sshd_config_readonly
 	fi
 	if ${@bb.utils.contains('PACKAGECONFIG','hostkey-ed25519','true','false',d)}; then
-		echo "HostKey /var/run/ssh/ssh_host_ed25519_key" >> ${D}${sysconfdir}/ssh/sshd_config_readonly
+		echo "HostKey ${OPENSSH_HOST_KEY_DIR_READONLY_CONFIG}/ssh_host_ed25519_key" >> ${D}${sysconfdir}/ssh/sshd_config_readonly
 	fi
 }
 
Signature · 1 line
2.43.0
#3 lore raw

Hi,

Quoted 18 lines · Patrick Vogelaar via lists.openembedded.org

This patch adds a variable for the key directory path. This is especially useful when working with a read-only file system where you want to specify the location e.g. on a r/w partition. To be consistent, the change was also done for the read write path.

For changing the path simply create a bbappend and override the variable.

---
 .../openssh/openssh_10.2p1.bb                    | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
meta/recipes-connectivity/openssh/openssh_10.2p1.bb +0 -0
index 866129573f..d8ea487ae3 100644

meta/recipes-connectivity/openssh/openssh_10.2p1.bb CACHED_CONFIGUREVARS += "ac_cv_path_PATH_PASSWD_PROG=${bindir}/passwd" · line 104

Quoted 6 lines
meta/recipes-connectivity/openssh/openssh_10.2p1.bb +3 -0
@@ -99,6 +99,10 @@ CACHED_CONFIGUREVARS += "ac_cv_path_PATH_PASSWD_PROG=${bindir}/passwd"
 # We don't want to depend on libblockfile
 CACHED_CONFIGUREVARS += "ac_cv_header_maillock_h=no"
 
+# This allows overriding the key location
+OPENSSH_HOST_KEY_DIR_READONLY_CONFIG ?= "/var/run/ssh"
+OPENSSH_HOST_KEY_DIR ?= "/etc/ssh"

Thanks for the patch, it was merged in master. As a follow-up, could you send patches to document these variables in
https://git.yoctoproject.org/yocto-docs/tree/documentation/ref-manual/variables.rst?

And add a note here
https://git.yoctoproject.org/yocto-docs/tree/documentation/migration-guides/release-notes-6.0.rst#n24?

Thanks!
Antonin

Signature · 3 lines
Antonin Godard, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#4 lore raw

Hi Antonin,

Quoted 35 lines

Antonin Godard <[email protected]> hat am 29.01.2026 12:17 CET geschrieben:

Hi,

Quoted 18 lines · Patrick Vogelaar via lists.openembedded.org

This patch adds a variable for the key directory path. This is especially useful when working with a read-only file system where you want to specify the location e.g. on a r/w partition. To be consistent, the change was also done for the read write path.

For changing the path simply create a bbappend and override the variable.

---
 .../openssh/openssh_10.2p1.bb                    | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
meta/recipes-connectivity/openssh/openssh_10.2p1.bb +0 -0
index 866129573f..d8ea487ae3 100644

meta/recipes-connectivity/openssh/openssh_10.2p1.bb CACHED_CONFIGUREVARS += "ac_cv_path_PATH_PASSWD_PROG=${bindir}/passwd" · line 104

Quoted 6 lines
meta/recipes-connectivity/openssh/openssh_10.2p1.bb +3 -0
@@ -99,6 +99,10 @@ CACHED_CONFIGUREVARS += "ac_cv_path_PATH_PASSWD_PROG=${bindir}/passwd"
 # We don't want to depend on libblockfile
 CACHED_CONFIGUREVARS += "ac_cv_header_maillock_h=no"
 
+# This allows overriding the key location
+OPENSSH_HOST_KEY_DIR_READONLY_CONFIG ?= "/var/run/ssh"
+OPENSSH_HOST_KEY_DIR ?= "/etc/ssh"

Thanks for the patch, it was merged in master. As a follow-up, could you send patches to document these variables in
https://git.yoctoproject.org/yocto-docs/tree/documentation/ref-manual/variables.rst?

Quoted 2 lines

And add a note here
https://git.yoctoproject.org/yocto-docs/tree/documentation/migration-guides/release-notes-6.0.rst#n24?

I will send a patch that documents the variable. But I don't know where to put it in the release notes. Can you guide me to the section where this would fit in.

Quoted 8 lines

Thanks!
Antonin

Signature · 3 lines
Antonin Godard, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

Thanks
Patrick

#5 lore raw

Hi,

On Sat Jan 31, 2026 at 11:01 AM CET, Patrick Vogelaar via lists.openembedded.org wrote:
[...]

Quoted 8 lines
Quoted 6 lines

Thanks for the patch, it was merged in master. As a follow-up, could you send patches to document these variables in
https://git.yoctoproject.org/yocto-docs/tree/documentation/ref-manual/variables.rst?

And add a note here
https://git.yoctoproject.org/yocto-docs/tree/documentation/migration-guides/release-notes-6.0.rst#n24?

I will send a patch that documents the variable. But I don't know where to put it in the release notes. Can you guide me to the section where this would fit in.

Yes, it should be in this document:
https://git.yoctoproject.org/yocto-docs/tree/documentation/migration-guides/release-notes-6.0.rst

Under the bullet point "New variables"

Thanks,
Antonin

Signature · 3 lines
Antonin Godard, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com