Skip to contentSkip to conversation

openssh: Be more restrictive on private key file permissions

PATCH Superseded Khem Raj 2 participants 2 messages Oct 10, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Khem Raj

author
#0 lore raw

PATCH 1/1 openssh: Be more restrictive on private key file permissions

Sometimes default permissions on filesystems can be more permissive e.g. 0644, this can make the private key file created here to inherit those permissions and these permissions can then cause ssh server to not allow ssh connections due to non-secure permissions on file.

---
 meta/recipes-connectivity/openssh/openssh/sshd_check_keys | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
meta/recipes-connectivity/openssh/openssh/sshd_check_keys +1 -1
index 606d1894b55..fae2bc5d16c 100644
@@ -8,7 +8,7 @@ generate_key() {
     mkdir -p "$DIR"
     rm -f ${FILE}.tmp
     ssh-keygen -q -f "${FILE}.tmp" -N '' -t $TYPE
-
+    chmod 0600 "$FILE.tmp"
     # Atomically rename file public key
     mv -f "${FILE}.tmp.pub" "${FILE}.pub"
 
#1 lore raw

Khem Raj via lists.openembedded.org schrieb am Do 10. Okt, 11:51 (GMT):

meta/recipes-connectivity/openssh/openssh/sshd_check_keys generate_key() { · line 11

Quoted 5 lines
     mkdir -p "$DIR"
     rm -f ${FILE}.tmp
     ssh-keygen -q -f "${FILE}.tmp" -N '' -t $TYPE
meta/recipes-connectivity/openssh/openssh/sshd_check_keys +1 -1
-
+    chmod 0600 "$FILE.tmp"

Or maybe (umask 700 && ssh-keygen -q -f "${FILE}.tmp" -N '' -t $TYPE) or do at least chmod go= "$FILE.tmp" to not add a user write permission ssh-keygen might not have set.

Kind regards, Jörg