In order to secure the Linux shell on the dedicated server we need to change our default SSH port. We get port 22 as the default port during installation. This fact is not hidden from hackers. These hackers always try to use this default port to perform their attacks and login attempts. You can prevent such attempts by simply changing encrypted remote connections.
How do I change the default SSH port?
Let’s see how we can change the default SSH port to secure the Linux shell in Dedicated Server. Follow these steps correctly.
- Open the main configuration file of the SSH daemon. You can open it with any text editor. To open this file, you need to enter the following command.
#VI / ETC / SSH / SSHD_CONFIG
- After opening the file, you’ll need to make the following changes.
- How you are in sshd_config File, please find the line beginning with Port 22Don’t forget to put a hashtag (#) in front of the line.
- Now you need to add a new port line and specify a new port to connect to SSH. Make sure to add the new port line below the #port 22 lines.
- When choosing a new port, make sure it has to be higher than 1024. According to the standards, you can select a port up to 65535 / TCP.
For example, here we’re changing port 22 to the new port 15500. After making the above changes, restart the SSH daemon to reflect changes.
Now run the SS Command. This action will Confirm that the SSH port was changed successfully.
# systemctl restart ssh # netstat -tlpn | grep ssh # ss -tlpn | grep ssh
Relaxing SE Linux Policy
Install the policycoreutils package CentOS or RHEL Linux based distributions. To relax the SELinux policy, add the following rules to make the SSH daemon bind to the new port.
# yum install policycoreutils # semanage port -a -t ssh_port_t -p tcp 15500 # semanage port -m -t ssh_port_t -p tcp 15500 # systemctl restart sshd # netstat -tlpn | grep ssh # ss -tlpn | grep ssh
Ashok Arora is the CEO and founder of eWebGuru, a leading Indian web hosting company. He is a tech enthusiast with over 25 years of internet and technology experience.
Ashok holds a Masters in Electronics from a leading Indian university.
Ashok loves to write on the cloud, servers, data centers and virtualization technology.