ha-remote-vpn-addon/rootfs/etc/services.d/ssh/run
2024-01-01 17:32:37 +01:00

55 lines
1.6 KiB
Plaintext
Executable file

#!/command/with-contenv bashio
if [ ! -e "/config/ssh" ]
then
bashio::log.info "Initialize SSH configuration..."
rsync -a /srv/ssh/ /config/ssh/
bashio::log.info "done."
else
bashio::log.info "SSH configuration already initialized"
fi
# Generate key if missing
if [ -z "$( ls /config/ssh/*_key 2> /dev/null )" ]
then
bashio::log.info "Generate SSH host keys..."
ssh-keygen -A
cp -p /etc/ssh/*_key* /config/ssh/
bashio::log.info done.
else
bashio::log.info "Existing SSH host keys present, reuse it"
# Install host keys
bashio::log.info "Install SSH host keys... "
cp -p /config/ssh/*_key /config/ssh/*_key.pub /etc/ssh/
chown root: /etc/ssh/*_key*
chmod 600 /etc/ssh/*_key
chmod 644 /etc/ssh/*_key.pub
bashio::log.info done.
fi
# Install configuration
if [ -n "$( ls /config/ssh/*.conf 2> /dev/null )" ]
then
bashio::log.info "Install custom SSH configuration files... "
cp -p /config/ssh/*.conf /etc/ssh/sshd_config.d/
bashio::log.info done.
else
bashio::log.info "No custom SSH configuration files found. Put it in addon_config/<addon slug>/ssh if need (with .conf extension)."
fi
# Install authorized_keys file
if [ -e /config/ssh/authorized_keys ]
then
bashio::log.info "Install SSH authorized keys (from /config/ssh/authorized_keys file)... "
cat /config/ssh/authorized_keys > /root/.ssh/authorized_keys
chmod 644 /root/.ssh/authorized_keys
bashio::log.info done.
else
bashio::log.info "No SSH authorized keys to install. Put it in addon_config/<addon slug>/authorized_keys file."
fi
# Start SSH
bashio::log.info "Start SSH service... "
exec /usr/sbin/sshd -f /etc/ssh/sshd_config -D