29 lines
680 B
Bash
Executable File
29 lines
680 B
Bash
Executable File
#!/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
|