How to change the SSH port
- Log in to your server using the current SSH port (default 22).
Note that you should not close this SSH connection until you have verified that you can access SSH on the new port number. - Open / etc/ssh/sshd_config
vi /etc/ssh/sshd_config
- Set your Port. For example 1234
Port 1234
- Restart SSHD
/scripts/restartsrv_sshd
or
sudo systemctl restart ssh.service
- Configure any firewalls with the new SSH port.
- Test SSH with new port 1234
ssh USER@HOSTNAME -p1234
Use your USER and HOSTNAME and the password and confirm new port.
If the SSH test on the new port is successful you can close the connection. If it is not successful, this SSH connection should not be closed until the SSH test on the new port is successful. Else revert the port to previous state and restart.
find / -name “sshd_config” -print
/usr/share/openssh/sshd_config
/etc/ssh/sshd_config
find / -name “sshd_config” 2>/dev/null
vi /usr/share/openssh/sshd_config
vi /etc/nftables.conf
ufw allow 1234/tcp
vi /etc/services
systemctl restart ssh
service ssh restart
systemctl restart ssh.service
ssh root@server_ip -p NEW_PORT
ssh root@123.512.11.6 -p 1234