How to change the default SSH port on a Linux VPS/Server

There are many ways to secure your Linux vps/server. 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/server. One of the major benefits of changing the default SSH port is to avoid being scanned by the casual 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.

In this article we will show you how to change the default SSH port, to strengthen the security of your Linux vps/server.

First of all, login to your server via SSH as user root

ssh root@IP_Address

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

Once you are logged in to the vps/server as user root update the installed packages.
CentOS / Fedora

yum update -y

Ubuntu / Debian

apt-get update $$ apt-get upgrade

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

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.

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/server. You should also check if the port is not closed in your server firewall.

Now, restart the SSH service for the changes to take effect.

service sshd restart

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.

  • SSH
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Directory and File Structure - Linux

Directory/Folder StructureFrom amongst the several directories found within your cPanel account,...

PHP Parse error: syntax error, unexpected $end

This error is typically caused by a missing } used in PHP to denote content belonging to a WHILE,...

How to drop tables from a database in phpMyAdmin?

This article will demonstrate how to drop (permanently delete) tables from a database in...

Optimizing Magento

Magento is a very popular eCommerce application. It offers a great deal of customization and...

Optimizing Joomla

Joomla is a popular CMS that is highly extensible and customizable. The following are suggestions...

Powered by WHMCompleteSolution