Change the SSH Port in CentOS and Red Hat
This article explains how to change the default Secure Shell (SSH) port on a CentOS® or Red Hat® Enterprise Linux® server.
Open and edit the SSH daemon configuration file
Run the following command to open the sshd_config file:
Use the arrow keys to scroll through the file until you locate the following text:
Place the cursor on the line below #Port 22 and press the i key to enter Insert Mode.
Press the Enter key to create a new line and type
Port <Specified Port Number>
.Port 2021
is the new SSH port in the following example:Press the Esc key to exit Insert Mode. Next, quit
vi
by typing:wq
and pressing the Enter key.
Bind SSH daemon to the new port
Install the policycoreutils package to bind the SSH daemon to the new SSH port by using the following command:
Type
y
and press the Enter key to continue with the installation. When this task completes, add the following rules to ensure that the SSH daemon binds with the specified port:Next restart the SSH daemon:
Verify the bind to the new port
Ensure that the port changes took effect by using either the netstat or ss command as shown in the following example:
As you can see, both commands show that Port 2021
is now in place.
Update your firewall
Update your firewall to ensure that incoming connections are allowed to the newly specified port. Enter the following two lines:
Comments
Post a Comment