Back up sshd_config
$ sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
Edit config to change port and disallow password auth
$ sudo nano /etc/ssh/sshd_config
Find the following line:
# Port 22
and change to something like:
Port 2244
Find the folling line:
#PermitRootLogin yes
and change to:
PermitRootLogin no
Exit and save.
Reload sshd and DO NOT EXIT YOUR SESSION
$ systemctl reload sshd
Open a new terminal window. In the new window, we need to begin a new connection to our server, using the new port number
# ssh [email protected] -p 2244
If you are able to connect, you may close your original terminal session. If not, recheck your sshd_config.
If you don't want to type in your port number in the future for connections to this server, you may modify your .ssh/config file to add something like the following:
Host yourserver.domain.com
Port 2244