Write ssh information in a writable area.
This commit is contained in:
2
etc/ssh/sshd_config.d/10-stormux-hostkeys.conf
Normal file
2
etc/ssh/sshd_config.d/10-stormux-hostkeys.conf
Normal 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
|
||||
5
etc/systemd/system/sshd.service.d/stormux-hostkeys.conf
Normal file
5
etc/systemd/system/sshd.service.d/stormux-hostkeys.conf
Normal file
@@ -0,0 +1,5 @@
|
||||
[Unit]
|
||||
Wants=
|
||||
Wants=stormux-sshd-hostkeys.service ssh-access.target
|
||||
After=
|
||||
After=network.target stormux-sshd-hostkeys.service
|
||||
7
etc/systemd/system/stormux-sshd-hostkeys.service
Normal file
7
etc/systemd/system/stormux-sshd-hostkeys.service
Normal 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
|
||||
28
usr/lib/stormux/stormux_sshd_hostkeys.sh
Executable file
28
usr/lib/stormux/stormux_sshd_hostkeys.sh
Executable 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
|
||||
Reference in New Issue
Block a user