2016-11-28 14:13:18 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
if [ ! -d /data/ssh ]; then
|
|
|
|
mkdir -p /data/ssh
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f /data/ssh/ssh_host_ed25519_key ]; then
|
|
|
|
echo "Generating /data/ssh/ssh_host_ed25519_key..."
|
2019-04-04 07:09:38 +02:00
|
|
|
ssh-keygen -t ed25519 -f /data/ssh/ssh_host_ed25519_key -N "" > /dev/null
|
2016-11-28 14:13:18 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f /data/ssh/ssh_host_rsa_key ]; then
|
|
|
|
echo "Generating /data/ssh/ssh_host_rsa_key..."
|
|
|
|
ssh-keygen -t rsa -b 2048 -f /data/ssh/ssh_host_rsa_key -N "" > /dev/null
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f /data/ssh/ssh_host_dsa_key ]; then
|
|
|
|
echo "Generating /data/ssh/ssh_host_dsa_key..."
|
|
|
|
ssh-keygen -t dsa -f /data/ssh/ssh_host_dsa_key -N "" > /dev/null
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f /data/ssh/ssh_host_ecdsa_key ]; then
|
|
|
|
echo "Generating /data/ssh/ssh_host_ecdsa_key..."
|
|
|
|
ssh-keygen -t ecdsa -b 256 -f /data/ssh/ssh_host_ecdsa_key -N "" > /dev/null
|
|
|
|
fi
|
|
|
|
|
2021-05-13 14:11:28 +02:00
|
|
|
if [ -e /data/ssh/ssh_host_ed25519_cert ]; then
|
|
|
|
SSH_ED25519_CERT=${SSH_ED25519_CERT:-"/data/ssh/ssh_host_ed25519_cert"}
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -e /data/ssh/ssh_host_rsa_cert ]; then
|
|
|
|
SSH_RSA_CERT=${SSH_RSA_CERT:-"/data/ssh/ssh_host_rsa_cert"}
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -e /data/ssh/ssh_host_ecdsa_cert ]; then
|
|
|
|
SSH_ECDSA_CERT=${SSH_ECDSA_CERT:-"/data/ssh/ssh_host_ecdsa_cert"}
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -e /data/ssh/ssh_host_dsa_cert ]; then
|
|
|
|
SSH_DSA_CERT=${SSH_DSA_CERT:-"/data/ssh/ssh_host_dsa_cert"}
|
|
|
|
fi
|
|
|
|
|
2019-07-07 03:57:53 +02:00
|
|
|
if [ -d /etc/ssh ]; then
|
|
|
|
SSH_PORT=${SSH_PORT:-"22"} \
|
2019-10-12 17:45:00 +02:00
|
|
|
SSH_LISTEN_PORT=${SSH_LISTEN_PORT:-"${SSH_PORT}"} \
|
2021-05-13 14:11:28 +02:00
|
|
|
SSH_ED25519_CERT="${SSH_ED25519_CERT:+"HostCertificate "}${SSH_ED25519_CERT}" \
|
|
|
|
SSH_RSA_CERT="${SSH_RSA_CERT:+"HostCertificate "}${SSH_RSA_CERT}" \
|
|
|
|
SSH_ECDSA_CERT="${SSH_ECDSA_CERT:+"HostCertificate "}${SSH_ECDSA_CERT}" \
|
|
|
|
SSH_DSA_CERT="${SSH_DSA_CERT:+"HostCertificate "}${SSH_DSA_CERT}" \
|
2021-06-01 21:55:17 +02:00
|
|
|
SSH_MAX_STARTUPS="${SSH_MAX_STARTUPS:+"MaxStartups "}${SSH_MAX_STARTUPS}" \
|
|
|
|
SSH_MAX_SESSIONS="${SSH_MAX_SESSIONS:+"MaxSessions "}${SSH_MAX_SESSIONS}" \
|
2022-05-31 20:42:19 +02:00
|
|
|
SSH_INCLUDE_FILE="${SSH_INCLUDE_FILE:+"Include "}${SSH_INCLUDE_FILE}" \
|
2022-03-31 05:15:36 +02:00
|
|
|
SSH_LOG_LEVEL=${SSH_LOG_LEVEL:-"INFO"} \
|
2019-07-07 03:57:53 +02:00
|
|
|
envsubst < /etc/templates/sshd_config > /etc/ssh/sshd_config
|
|
|
|
|
|
|
|
chmod 0644 /etc/ssh/sshd_config
|
|
|
|
fi
|
|
|
|
|
2016-11-28 14:13:18 +01:00
|
|
|
chown root:root /data/ssh/*
|
|
|
|
chmod 0700 /data/ssh
|
|
|
|
chmod 0600 /data/ssh/*
|