Changing the default SSH port from 22 reduces automated brute-force attacks.
Choose a Port
Pick an unused port number between 1024 and 65535 (e.g., 2222).
Configure
Edit /etc/ssh/sshd_config:
Port 2222Update Firewall
# UFW
ufw allow 2222/tcp
ufw delete allow 22/tcp
# firewalld
firewall-cmd --permanent --add-port=2222/tcp
firewall-cmd --permanent --remove-service=ssh
firewall-cmd --reloadRestart SSH
systemctl restart sshdTest Before Disconnecting
Open a new terminal and connect on the new port:
ssh -p 2222 user@YOUR_IP_ADDRESSOnly close your current session after confirming the new port works.