diff --git a/bin/first-install/setup_ssh.sh b/bin/first-install/setup_ssh.sh index c327341..ec1e744 100644 --- a/bin/first-install/setup_ssh.sh +++ b/bin/first-install/setup_ssh.sh @@ -2,7 +2,21 @@ echo -e "${PURPLE}${BOLD}Setup SSH${RESET}" -SSH_PORT=$((RANDOM % (65536 - 1024 + 1) + 1024)) +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 + 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 @@ -10,4 +24,4 @@ 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}" \ No newline at end of file +echo -e "${ORANGE}${BOLD}Store the ssh port ${SSH_PORT} somewhere safe${RESET}"