re-order ssh config code

and add log info about temp key use
This commit is contained in:
macmpi 2023-05-12 08:41:41 +02:00
parent c41be0072c
commit fa08356540
2 changed files with 18 additions and 16 deletions

Binary file not shown.

View File

@ -79,6 +79,19 @@ rc-service networking start
## Setup temporary SSH server (root login, no password) ## Setup temporary SSH server (root login, no password)
## we use some bundled or optionaly provided keys to avoid generation at boot and save time ## we use some bundled or optionaly provided keys to avoid generation at boot and save time
apk add openssh apk add openssh
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.orig
cp /etc/conf.d/sshd /etc/conf.d/sshd.orig
cat <<-EOF >> /etc/ssh/sshd_config
AuthenticationMethods none
PermitEmptyPasswords yes
PermitRootLogin yes
Banner /tmp/.trash/banner
EOF
cat <<-EOF >> /etc/conf.d/sshd
sshd_disable_keygen=yes
EOF
# banner file # banner file
cat <<-EOF > /tmp/.trash/banner cat <<-EOF > /tmp/.trash/banner
@ -90,26 +103,15 @@ cat <<-EOF > /tmp/.trash/banner
# bundled temporary keys are moved in RAM /tmp so they won't be stored # bundled temporary keys are moved in RAM /tmp so they won't be stored
# within permanent config later (new ones will then be generated) # within permanent config later (new ones will then be generated)
mv /etc/ssh/ssh_host_*_key* /tmp/.trash/. mv /etc/ssh/ssh_host_*_key* /tmp/.trash/.
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.orig
cat <<-EOF >> /etc/ssh/sshd_config
AuthenticationMethods none
PermitEmptyPasswords yes
PermitRootLogin yes
Banner /tmp/.trash/banner
EOF
# inject optional custom keys (those might be stored) # inject optional custom keys (those might be stored)
if ! install -m600 "${ovlpath}"/ssh_host_*_key* /etc/ssh/; then if ! install -m600 "${ovlpath}"/ssh_host_*_key* /etc/ssh/; then
echo "HostKey /tmp/.trash/ssh_host_ed25519_key" >> /etc/ssh/sshd_config logger -st ${0##*/} "Using bundled ssh keys from RAM..."
echo "HostKey /tmp/.trash/ssh_host_rsa_key" >> /etc/ssh/sshd_config cat <<-EOF >> /etc/ssh/sshd_config
HostKey /tmp/.trash/ssh_host_ed25519_key
HostKey /tmp/.trash/ssh_host_rsa_key
EOF
fi fi
cp /etc/conf.d/sshd /etc/conf.d/sshd.orig
cat <<-EOF >> /etc/conf.d/sshd
sshd_disable_keygen=yes
EOF
rc-service sshd start rc-service sshd start
## Prep for final post-cleanup ## Prep for final post-cleanup