Yazı Boyutu:

Introduction
SSH, or Secure Shell, is an extremely powerful protocol that allows a user to communicate with remote servers over a totally secure connection. SSH is extensively utilized for purposes of management and maintenance on Linux and Unix-based operating systems. However, it is very much used by malicious users to gain access to the system, hence the use for additional security measures on it. One such measure involves changing the port of SSH.

The article will be detailed about the changes in the SSH port, why port changing is essential to security, and other ways to perform optimizations.

1. Why Change SSH Port?
It is very well known that SSH by default runs on port 22. This is the port widely known around the world as a port that is often targeted by scanning or brute force attacks. An attack would comprise attacking your SSH port and guessing the passwords on it to get into the workstation. Changing the default port will change the port that would be the target to automated scanning tools, and it will less probably be attacked.

Port change doesn't guarantee total security, but it can, especially when you have an evil user scouting your system, misdirect their attention and keep some attacks away.

2. Changing SSH Port
A. Steps Required to Change SSH Port
SSH port can be changed by going through the following steps:

1. Edit SSH Configuration File
The very first step is editing the SSH configuration file. This file contains all of the instructions about how the SSH service works, and is usually found at /etc/ssh/sshd_config.

To edit, run the following command:

sudo nano /etc/ssh/sshd_config
In it, you should look for line Port 22. If there is # sign at the beginning of the line, then it is a comment line and not active. You can change this line as follows:

Port 3458
Here, 3458 is your new port number. You can write any other port number you wish into this. But do keep in mind that the number has to be between 1024 and 49151 and should not be a port open on the server.

2. Use sed Command for Quick Port Number Change
You can use the sed command to quickly replace some text in a file. The following command replaces the default port 22 with 3458 in the sshd_config file:

sudo sed -i 's/^#Port 22/Port 3458/' /etc/ssh/sshd_config
What the command does:

sed -i: Modifies the file in-place.

's/^#Port 22/Port 3458/': This matches the line in the file that starts with #Port 22 and replaces it with Port 3458.

/etc/ssh/sshd_config: Path of the file to be edited.

3. Configuring Firewall Settings
Firewalls must have the new port open after changing the SSH port; otherwise, connecting through that port will not be possible.

For example, if you use firewalld, you can open the new port with the command below.

sudo firewall-cmd --permanent --add-port=3458/tcp