Menu
User

DropVPS Team

Writer: John hens

How to Change SSH Port on Red Hat

How to Change SSH Port on Red Hat

Publication Date

08/10/2025

Category

Articles

Reading Time

2 Min

Table of Contents

Changing the default SSH port can help reduce automated attacks targeting the default port 22.

Step 1: Connect to Your Server via SSH

To begin, securely log into your Red Hat server using SSH to ensure you have the necessary access for configuration changes:

ssh your-username@your-server-ip

Step 2: Open the SSH Configuration File

Next, open the SSH daemon configuration file where the port setting is located, so you can edit it:

sudo vi /etc/ssh/sshd_config

Step 3: Change the SSH Port Number

Changing the default SSH port from 22 to a custom port reduces unauthorized access attempts and enhances your server’s security.

Inside the file, find this line:

#Port 22

Uncomment it and replace 22 with your chosen port number, for example:

Port 2222

Save and close the file.

Step 4: Allow the New Port in Your Firewall

Update your firewall settings to allow incoming connections on the new SSH port so your server remains accessible:

sudo firewall-cmd --permanent --add-port=2222/tcp
sudo firewall-cmd --reload

Step 5: Restart the SSH Service

Restart the SSH service to apply the new configuration and enable the new port for incoming connections:

sudo systemctl restart sshd

Step 6: Test the New SSH Port

Before closing your current session, test the new SSH port by connecting with the -p flag to confirm everything works:

ssh -p 2222 your-username@your-server-ip

 

Linux VPS
U
Loading...

Related Posts

How to Change SSH Port on Red Hat