How to change SSH Port on CentOS 7/AlmaLinux 8/9

Here's how to change SSH port on CentOS 7 /Almalinux 8/9 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 then type 'Port' to find #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 

$ sudo systemctl restart sshd.service

 

Check if firewalld is running, you'll need to whitelist the new port number

$ sudo firewall-cmd --state

if the output is 'running' , follow the next steps.

 

1. Add the custom port to firewalld:

$ sudo firewall-cmd --permanent --add-port=1234/tcp

2. Reload the firewall configurations:

$ sudo 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.

  • centos 7, ssh, port
  • 3048 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.