Write ssh information in a writable area.

This commit is contained in:
Storm Dragon
2026-04-21 16:18:23 -04:00
parent 284662ff49
commit 93b7ad2ae5
4 changed files with 42 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
HostKey /home/stormux/.local/etc/ssh/ssh_host_ed25519_key
HostKey /home/stormux/.local/etc/ssh/ssh_host_rsa_key

View File

@@ -0,0 +1,5 @@
[Unit]
Wants=
Wants=stormux-sshd-hostkeys.service ssh-access.target
After=
After=network.target stormux-sshd-hostkeys.service

View File

@@ -0,0 +1,7 @@
[Unit]
Description=Generate persistent Stormux SSH host keys
RequiresMountsFor=/home/stormux/.local/etc/ssh
[Service]
Type=oneshot
ExecStart=/usr/lib/stormux/stormux_sshd_hostkeys.sh

View File

@@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -euo pipefail
hostKeyDir="${STORMUX_SSH_HOSTKEY_DIR:-/home/stormux/.local/etc/ssh}"
generate_host_key() {
local keyType="$1"
local filePath="$2"
shift 2
if [[ -f "$filePath" ]]; then
return 0
fi
rm -f "${filePath}.pub"
ssh-keygen -q -t "$keyType" "$@" -N "" -f "$filePath"
}
if [[ "${EUID}" -eq 0 ]]; then
install -d -o root -g root -m 700 "$hostKeyDir"
else
install -d -m 700 "$hostKeyDir"
fi
generate_host_key ed25519 "${hostKeyDir}/ssh_host_ed25519_key"
generate_host_key rsa "${hostKeyDir}/ssh_host_rsa_key" -b 3072
chmod 600 "${hostKeyDir}"/ssh_host_*_key
chmod 644 "${hostKeyDir}"/ssh_host_*_key.pub