in Linux

How to change SSH port on CentOS 7

4.00
1 Star2 Stars3 Stars4 Stars5 Stars
Ratings: 4.00/5 from 1 users.
Loading...

To change the default SSH port, the first thing you want to do is backup the current SSH configuration file on your system. To do that, run the commands below.

sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak

This creates a new named sshd_config.bak with the current settings of the sshd_config file. If something goes wrong, you can then restore the file from the backup.

Next, run the commands below to open the default SSH configuration file /etc/ssh/sshd_config

# nano /etc/ssh/sshd_config

Run ssh on a non-standard port # 2022 using Port option

Set Port for example to 2022:
Port 2022

Save and close the file.

Then restart the SSH service.

service sshd reload

if your have firewall system installed on your server, you must allow incoming and outgoing data in the new port. So you should add your new port in “TCP_IN” and “TCP_OUT”.

Related Posts

Add a Comment

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