Modify the Default SSH Port on any Linux Distribution - Step by Step Process ?








Secure Shell (SSH) is the most popular method of remotely connecting to your Linux Machine. The protocol offers strong authentication hence maintaining the security and integrity of your Linux computer.

SSH utilizes strong encryption and allows users or automated processes to access, interact and even transfer files from a server. Once connected, a user can issue Linux commands to perform mission critical operations.

By default, port 22 is used to establish an SSH connection. This port is automatically configured during the installation of your operating system. 

To reduce the number of brute force attacks, you can configure another port for SSH access. 

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related Linux queries.

In this context, you will learn how to change the Default SSH Port on your Ubuntu Linux System.


How to change the SSH port in Linux ?

To implement this, follow the steps given below.

1. Log on to the server as an administrator.

2. Open the SSH configuration file sshd_config with the text editor vi:

$ vi /etc/ssh/sshd_config

3. Search for the entry Port 22.

4. Replace port 22 with a port between 1024 and 65536

5. Save the file.

6. Restart the service.

On Ubuntu

$ service ssh restart

On CentOS 7

$ systemctl restart sshd

To establish an SSH connection after this change, enter the following command:

$ ssh root@IP_address_of_the_server -p NewPort


To update your firewall config,

You can change the number "22" in the commands listed below to the new port you've set above and then run the command.

On Ubuntu, run the ufw firewall command:

$ ufw allow 22

On CentOS 7, use the firewalld commands below:

$ firewall-cmd --zone=public --add-port=22/tcp --permanent
$ firewall-cmd --reload

On Debian and CentOS 6 System, run the iptables commands below:

$ iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
$ service iptables save
$ service iptables reload


[Need urgent assistance in fixing Linux SSH errors? We can help you. ]



Conclusion

This article covers how to change the default SSH port on your Linux machine.

To change the default port the SSHD daemon is listening on.

We can edit the configuration file using a nano editor:

$ sudo nano /etc/ssh/sshd_config

Once you make a change to the SSHD daemon configuration file, you should restart the services to reload the new changes.

$ sudo service sshd restart

For Linux Tutorials

We create Linux HowTos and Tutorials for Sys Admins. Visit us on LinuxAPT.com

Also for Tech related tips, Visit forum.outsourcepath.com or General Technical tips on www.outsourcepath.com