manually enter ssh port

This commit is contained in:
Valentin 2024-11-28 22:53:30 +01:00
parent 5436760bf6
commit 8948238b45
1 changed files with 16 additions and 2 deletions

View File

@ -2,7 +2,21 @@
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
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