How to changing the SSH port in CentOS

Many Linux-based operating systems allow you to change the SSH port. This article will guide you through the process of changing your SSH port.

This article tells you how to increase your security by changing the SSH port number to a custom number. This is the main reason for protection, as hackers can break into your server through the default port 22 and take over your system. In this case, changing the SSH port will make it impossible for them to do so because they don’t know which port to use.

What is SSH?

It is a protocol that enables data to be exchanged securely between two systems. SSH uses cryptography and is an abbreviation for Secure Shell, which means that data is encrypted and thus secure. It was initially developed as a replacement for Telnet and other insecure remote access protocols. However, there are many use cases of SSH, and it can be used to remotely log in to another computer, transfer files securely over the network, and other ways.

What are the benefits of using SSH?

SSH is a protocol that provides secure access to remote computers. The benefits of using SSH are numerous. One of the most important is the security it provides. If you are remotely connecting to a Linux-based Server, SSH encrypts all traffic so that no one can intercept your data and steal your information.

I will help you to change the SSH port in CentOS 7. Let’s get started.

 

Step 1 — The first step is to open up Secure Shell (SSH) configuration file

[root@my ~]# vi /etc/ssh/sshd_config

Search for the entry Port 22

#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

Replace port 22 with a port between 1024 and 65536, and It is recommended that you use a random number.

Port 2288
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

Step 2 — Update SELinux configuration.

[root@my ~]# semanage port -a -t ssh_port_t -p tcp 2288
if prompted with an error that says: semanage command not found. 

Step 3 Run the following commands to install semanage on CentOS 7

root@us1 ~]# yum provides /usr/sbin/semanage
root@us1 ~]# yum whatprovides /usr/sbin/semanage
root@us1 ~]# yum install policycoreutils-python-utils
root@us1 ~]# yum install policycoreutils-python

Now semanage command on your CentOS 7 will work fine

Step 4 — If you’ve configured firewalls and want to ensure that SSH port 2288 is open. Otherwise, the “restart sshd.service” will lock down your ssh access.

Step 5 — Run the following commands to verify the port modification

[root@us1 ~]# ss -tlpn| grep ssh

output

[root@us1 ~]# ss -tlpn| grep ssh
LISTEN     0      128          *:2288                     *:*                   users:(("sshd",pid=10585,fd=3))
LISTEN     0      128       [::]:2288                  [::]:*                   users:(("sshd",pid=10585,fd=4))

Step 6 — Restart the SSH daemon

[root@us1 ~]# systemctl restart sshd.service

Secure Shell (SSH) is Now ready to send sensitive data across the internet while keeping it safe and private.

Are you in need of a firewall? CSF is the ideal firewall solution for CentOS 7 servers. This guide will walk you through installing and configuring the CSF firewall on your server.

Leave a Comment

− 2 = 7