Change SSH Port on CentOS
Change SSH Port on CentOS 8
First, create a backup of sshd_config.
# cp/etc/ssh/sshd_config/etc/ssh/sshd_config_backup
Then open your ssh configuration to change it
# sudo nano /etc/ssh/sshd_config
This command will open the SSH (SSHD) server configuration.
We make the following change to the sshd_config file
# SSH port
Port 11111 # port that needs to be changed
We then update the IPTABLES firewall by introducing a new SSHD port.
If you have your firewall turned off, you can skip this step.
If you are using centos 6, you can run this command
For centOS 6
# iptables -I INPUT -p tcp --dport 11111 --syn -j ACCEPT
# service iptables save
# semanage port -a -t ssh_port_t -p tcp 11111
For centOS 7/8
# firewall-cmd --add-port 11111/tcp --permanent
# firewall-cmd --add-port 11111/tcp
The configuration will start working after restarting SSH Server (SSHD) services or after restarting the server.
# service sshd resrtart
or
# systemctl restart sshd
If you have trouble getting to SSHD, you need to configure SELinux policy since you changed port 22 to 11111.
Run this command.
# semanage port -a -t ssh_port_t -p tcp 11111
Then restart the server.
# reboot