deployment_ddcdn_multisite/bin/first-install/setup_ssh.sh

29 lines
1022 B
Bash

#!/bin/bash
echo -e "${PURPLE}${BOLD}Setup SSH${RESET}"
echo -e "${PURPLE}${BOLD}Do you want to manually set the SSH port? (y/N)${RESET}"
read answer
if [[ "$answer" == "y" ]]; then
echo -e "${PURPLE}${BOLD}Enter the desired SSH port (between 1024 and 65535):${RESET}"
read port
# @ TODO : is manually setting port really working ?
if [[ "$port" =~ ^[0-9]+$ ]] && [ "$port" -ge 1024 ] && [ "$port" -le 65535 ]; then
SSH_PORT=$port
else
SSH_PORT=$((RANDOM % (65536 - 1024 + 1) + 1024))
echo -e "${ORANGE}${BOLD}Invalid port number. Using random port instead.${RESET}"
fi
else
SSH_PORT=$((RANDOM % (65536 - 1024 + 1) + 1024))
fi
touch /etc/ssh/sshd_config.d/custom.conf
echo "PermitRootLogin no" >> /etc/ssh/sshd_config.d/custom.conf
echo "PermitEmptyPasswords no" >> /etc/ssh/sshd_config.d/custom.conf
echo "Port ${SSH_PORT}" >> /etc/ssh/sshd_config.d/custom.conf
systemctl reload ssh
echo -e "${ORANGE}${BOLD}Store the ssh port ${SSH_PORT} somewhere safe${RESET}"