To change which port ssh listens on, you just need to edit the sshd_config file. The default directory for ssh configuration is /etc/ssh.
- First, backup the current configuration and use your favorite editor to change the Port line:root@root [~]# cd /etc/ssh/
root@root [/etc/ssh]# cp sshd_config sshd_config.save
root@root [/etc/ssh]# vi sshd_config - Now, locate the following line:#Port 22
- For this example, we’ll set it to port 4000, by replacing “Port 22” with “Port 4000“. *Note: Do not forget to remove the comment (#).Port 4000
root@root [/etc/ssh]# diff sshd_config sshd_config.save
13c13
< Port 4000
—
> #Port 22
root@root [/etc/ssh]# - Lastly, restart sshd and verify that it is now listening on the new port.root@root [/etc/ssh]# /etc/init.d/sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
root@root [/etc/ssh]# netstat -anp | grep sshd
tcp 0 0 0.0.0.0:4000 0.0.0.0:*
LISTEN 1605/sshd
And there you have it! You can set the port number to whichever port you prefer, but keep in ming that port numbers between 0 and 1,023 are reserved for existing system services. For this reason, you’re typically better off choosing a number above Port 1023.
If you enjoyed this article, then you’ll love Zalvis's Cloud Hosting platform. Turbocharge your website and get 24/7 support from our veteran team. Our world-class hosting infrastructure focuses on auto-scaling, performance, and security. Let us show you the Zalvis difference! Check out our services.