Today we’ll show you, how to change the default SSH port on Linux. Changing the default SSH port from the default 22 to another one, is one of the first things you should do to secure your Linux VPS. One of the major benefits of changing the default SSH port is to avoid being scanned by the causal port scans. Thousands of brute-force logins are attempting to gain access to servers around the world trying to login to the default SSH port looking for weak passwords on the default accounts. Some of them will even try to use usual variants such as port 222 or 2222. If you change the SSH port to a random number, for example 2569, you will get rid of most of these annoying, and sometimes dangerous brute-force attacks. Changing the default SSH port on Linux, is an easy task, carefully follow our tutorial bellow and you should have it done in less then 10 minutes.
In this article we will show you how to change the default SSH port, to strengthen the security of your Linux VPS.
1. Login via SSH
First of all, login to your server via SSH as user root
Note that if SSH is listening on the default port 22, there is no need to specify the port. When the port will be changed, you will need to specify if when logging to the server via SSH. For example, if SSH is listening on port 1012 we can login to the server using the following command:
ssh root@IP_Address -p1012
2. Updated Installed Packages
Once you are logged in to the VPS as user root update the installed packages.
CentOS / Fedora
yum update -y
Ubuntu / Debian
apt-get update $$ apt-get upgrade
3. Open the SSH Configuration File
Once the system is updated, open the SSH configuration file with your favorite text editor and find the lines that specifies the SSH port.
vim /etc/ssh/sshd_config #Port 22
4. Change SSH Port Number
Uncomment the relevant line by removing the # sign and change the default port 22 to the one that you want to use. In this article we will use port 1012.
Save the changes and exit.
NOTE: Before changing the port, you should make sure that the new port is free and it is not used by another service on your VPS. You should also check if the port is not closed in your server firewall.
5. Restart SSH Service
Now, restart the SSH service for the changes to take effect.
service sshd restart
6. Check SSH Port
Once restarted, SSH will listen on port 1012. You can check this by executing the following command in the terminal
netstat -tunlp |grep ssh tcp 0 0 0.0.0.0:1012 0.0.0.0:* LISTEN 497/sshd
According to the output of the netstat command, the SSH port is changed, and it is now listening on port 1012.
Of course you don’t have to change the default SSH port on Linux, if you use one of our Blazing-Fast VPS Hosting services, in which case you can simply ask our expert Linux admins to change the SSH port on Linux for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post, on how to change the default SSH port on Linux, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.