How to change the SSH connection port

  • Last updated: Oct 13, 2024
  • Views: 8
  • Author: Admin
How to change the SSH connection port

Hello colleagues.

In today's article, we will talk about how to change the default port for connecting to the server via SSH protocol in Linux distributions.

SSH stands for Secure Shell and is a network protocol through which users can remotely connect to servers. Connections between client and server are always encrypted, which makes the SSH protocol secure. Connections are made on port 22, this is the default port. However, using this port is not very secure because your server becomes vulnerable to many cyberattacks. Therefore, changing the default port is one of the best ways to protect your server.

 

We will be changing the port from 22 to 99.

The main thing is not to forget to disable SELinux in front of the robots or write the necessary rules into it so that you do not completely lose access to the server after your changes.

 

First of all, we need to open our new port on the Firewall for connecting via SSH, for this we use the command:

$. firewall-cmd --zone=public --add-port=99/tcp --permanent

The next step is to force the Firewall to reread all the rules so that our new rule takes effect, for this we use the command:

$. firewall-cmd --reload

linux ssh change port connection


 

Now let's change the default connection port. We will make changes in the main SSH configuration file called sshd_config.

Open the sshd_config file for editing with the command:

$. vi /etc/ssh/sshd_config

We look for the Port parameter in this file, remove the comment and change the values ​​​​from 22 to 99.

Port 99

linux ssh change port connection

Save the changes and close the file.

 

After the changes made, you need to restart the SSH service, for this we use the command:

$. sudo service sshd restart

 

Done, now you can open a new session only not with connection port 22, but already 99.


 

Thank you all, I hope my article was of some help to you.

 

SIMILAR ARTICLES