+44 74 1835 1231

How To Change SSH Port In CentOS 7

Tutorial Linux

August 5, 2020 by Harry

Change The SSH Port In CentOS

We are at your service by teaching you how to change the SSH port in the CentOS operating system. The default port of the SSH service is 22, and if we have it by default, hackers may be able to attack the server through port 22, take control of it, or cause irreparable damage to it. Therefore, we suggest that you change the default SSH port to increase the security of your server.

What Is SSH?

SSH means a secure shell, a free version of the SSH connection tool that allows a secure connection to the network. The SSH encrypts all transmitted data (including passwords), eliminating the possibility of others accessing the network data. SSH is a standard protocol for the encrypted exchange of information over a network. Using ssh service software, remote access to a computer on the network is provided.

SSH (uppercase) refers to the SSH protocol and ssh (lowercase) means remote communication software. One of the free software for establishing SSH connection, which is called Putty, allows connecting to Linux servers with commands.

Notes Before Changing The Default SSH Port

  • It is better to specify a 4 or 5 digit port. Also, remember to uses a free SSH port.
  • If a firewall is used in the data center network, be sure to inform the data center of the desired port to open it.
  • Be sure to write down the port you want to allocate to SSH.
  • Be careful to change the SSH port as any mistake may cause you to have trouble accessing the server.
  • If you do not use SELinux, you should just disable it to prevent any issue on the function of your server.

Steps To Change The SSH Port In CentOS

  1. Enter SSH with the help of PuTTY software.
  2. Disable SELinux
  3. Edit the sshd_config file and change port 22 to the desired port.
  4. Restart sshd service.

Use Putty To Connect The Server

You can the below educational link in order to learn how to use putty to connect to a Linux VPS.

https://operavps.com/how-to-use-putty-to-connecta–linux-vps-ssh/

Disable SELinux Before Changing SSH Port

To disable SELinux, open the below file and set the mode to disabled.

/etc/selinux/config

disable SELinux to change ssh port

Edit The sshd File To Change SSH Port

After entering SSH through Putty, go to sshd_config file editing mode with the following command.

nano /etc/ssh/sshd_config

open sshd to change ssh port

Note: If the nano package is not installed, try to install it with this command.

yum install nano

Next, we need to change the number 22 specified in the image above to another value (for example port 14252). We also need to remove the # character from the beginning of this line to include this line as an active operating command on the server.

change ssh port in sshd

Note: You should also add the new port to your firewall to prevent any disruption, using this command after changing SSH port.

sudo firewall-cmd --zone=public --permanent --add-port=14252/tcp

after you change ssh port, add it to firewall

Restart sshd Service

sudo systemctl restart sshd

To restart SSHD service use the below command and if you faced error with restarting this service, try to reboot the server. Once the server was ready, you can easily connect to the server through putty and the new port number should be used instead of port 22 but the case is, this time you are more secure than the last connection!

Summary

You can easily change the SSH port through the sshd_config file. The only thing that you should be careful of, is to add the new port number to your firewall before you apply the new setting to prevent any disruption in the function of the server.

I hope you have enjoyed this post and you’ve found your answers.
Please do not hesitate to share your opinions with us.

Was this post helpful?

About the Author Harry

I like to learn and to teach to make things easier

Leave a Reply

Your email address will not be published. Required fields are marked *