Change ssh port on centOS 8; Through this tutorial, we will learn how to change ssh port on centOS 8.

  • Step 1 – Backup Current SSH configuration
  • Step 2 – Change SSH service port
  • Step 3 – Allow new SSH port on SELinux
  • Step 4 – Open SSH port on Firewalld
  • Step 5 – Restart sshd service
  • Step 6 – Verify SSH Service

Step 1 – Backup Current SSH configuration

date_format=`date +%Y_%m_%d:%H:%M:%S`
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config_$date_format
$ ls /etc/ssh/sshd_config*
/etc/ssh/sshd_config /etc/ssh/sshd_config_2022_07_06:22:40:10

Step 2 – Change SSH service port

sudo vi /etc/ssh/sshd_config

Now the file has been opened with the above-given command. Search #Port 22 in that file:

#Port 22

Now remove # from this line and enter any port. We will put port 33000 in it:

Port 33000

Save the changes and close the file.

Step 3 – Allow new SSH port on SELinux

$ semanage port -l | grep ssh
ssh_port_t tcp 22
sudo semanage port -a -t ssh_port_t -p tcp 33000

Like now we have added the new port. We can use the command given below to verify it:

$ semanage port -l | grep ssh
ssh_port_t tcp 33000, 22

Step 4 – Open SSH port on Firewalld

Now the port we have added. For that we also need to do firewall configuration.

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

If Firewalld is not installed, use yum to install it and start the service:

sudo yum -y install firewalld
sudo systemctl enable --now firewalld
sudo firewall-cmd --add-port=33000/tcp --permanent
sudo firewall-cmd --reload

Step 5 – Restart sshd service

sudo systemctl restart sshd

Step 6 – Verify SSH Service

Finally, we have changed the SSH port. To verify this, you can use the below command:

$ netstat -tunl | grep 33000
tcp 0 0 0.0.0.0:33000 0.0.0.0:* LISTEN
tcp6 0 0 :::33000 :::* LISTEN 

Conclusion

Through this tutorial, we have learned how to change ssh port on centOS 8.

Читайте также:  Инструкция по переносу сайта на движке Joomla на хостинг

Как изменить SSH-порт в CentOS