The default SSH port on all Operating Systems is port 22. For security measures, change SSH port to prevent Brute Force Attacks.
Warning: By changing the SSH port, it may be necessary to change the firewall settings. This should be checked first.
The server’s SSH configuration file is located here: /etc/ssh/sshd_config
SSH into your server as the root user. Open the configuration file:
nano -w /etc/ssh/sshd_config
Line #13 shows the current configured port number. (ie. Port 22) meaning, SSH is currently using 22.
Change the numerical digits from 22 to your desired port number, for this example we will be using 3000.
After changing to your desire port, Press [CTRL] + X to save the changes. You’ll be prompted, “Save modified buffer (ANSWERING “No” WILL DESTROY CHANGES) ?” Press Y and then [Enter].
You’ll again be prompted, “File Name to Write: /etc/ssh/sshd_config” , simply press [Enter] at this time.
Restart the SSH daemon:
RHEL/Almalinux:
systemctl restart sshd
Debian/Ubuntu:
systemctl restart ssh
You should see that it was stopped and started successfully:
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
For good measure, let’s confirm the changes were made and it’s running properly.
netstat -tulpn |grep sshd
tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN 5622/sshd
tcp 0 0 :::3000 :::* LISTEN 5622/sshd
:3000 shows that it’s listening properly on 3000 now, rather than 22.
Now when connecting to your server use the newly configured port number.