Disable the SSH server is 'PORT_SSH' variable is set to an empty string

This commit is contained in:
Josh.5
2022-09-03 16:25:45 +12:00
parent e5bd4be2f9
commit 79cb946b01

View File

@@ -1,14 +1,21 @@
# Generate new SSH host keys if they dont exist
if [[ ! -f /etc/ssh/ssh_host_rsa_key ]]; then
echo "**** Generating SSH keys ****";
/usr/bin/ssh-keygen -A
echo "**** Configure SSH server ****"
if [[ "X${PORT_SSH:-}" != "X" ]]; then
# Generate new SSH host keys if they dont exist
if [[ ! -f /etc/ssh/ssh_host_rsa_key ]]; then
echo "**** Generating SSH keys ****";
/usr/bin/ssh-keygen -A
fi
mkdir -p /run/sshd
chmod 744 /run/sshd
echo "Set port to '${PORT_SSH}'"
sed -i "s|^# Port 22.*$|Port ${PORT_SSH}|" /etc/ssh/ssh_config
else
echo "Disable SSH server"
# Disable supervisord script
sed -i 's|^autostart.*=.*$|autostart=false|' /etc/supervisor.d/sshd.ini
fi
mkdir -p /run/sshd
chmod 744 /run/sshd
echo "**** Configure SSH service ****";
sed -i "s|^# Port 22.*$|Port ${PORT_SSH}|" /etc/ssh/ssh_config
echo "DONE"