How to change SSH Port on CentOS/AlmaLinux9/RockyLinux9/RHEL 9

Here's how to change SSH port on Almalinux/RHEL to increase your server security.

Changing the SSH port is one of the important steps to take once your server is deployed.

 

1. Edit SSH config file with nano or your preferred editor

$ nano /etc/ssh/sshd_config

2. Press CTRL+W to search and type Port to find the line #Port 22 in the config file

3. Replace #Port 22 with Port 1234 "remove the #" (and replace 1234 with a port number of your choice)

4. Press CTRL+X to exit the editor

5. Press Y and Enter to save the changes

6. Restart SSH service

$ sudo systemctl restart sshd.service

 

Firewall Configuration

Check if firewalld service is running on your system.

firewall-cmd --state

 

If the output is running , follow the next steps:

 

  1. Add the custom port to firewalld:
    firewall-cmd --permanent --add-port=1234/tcp​

    Note: Replace 1234 with your new port number.

  2. Reload the firewall configurations:
    firewall-cmd --reload​

 

If you've another firewall installed like CSF, make sure to open the new SSH port on CSF. 

 

HostRound Offers premium USA Dedicated Servers and VPS Hosting in the Netherlands and Dallas, TX.

  • ssh, RockyLinux, AlmaLinux
  • 9356 Users Found This Useful
Was this answer helpful?

Related Articles

How to reinstall an OS on my server?

If you already have an OS installed on your server and want to change or reinstall it, you can do...

How to set rDNS records for my dedicated server IPs?

You can update rDNS records of your server IPs from Client Area (One Portal) Log in to your...

How to set a rDNS/PTR record for my VPS?

Please open a support ticket and provide the rDNS record that you want to set and the IP address...

How DDoS protection works on a VPS?

Our DDoS mitigation system is powered by AI and is local with reduced latency. It can mitigate...

How many IPs I can add to my VPS?

The max IPv4 allocation for a VPS is 2 IPs. So you can add 1 additional IPv4 to your VPS.