centos7 update ssh port

0x01 open ports firewall

It should include 22 port

1
2
3
4
systemctl status firewalld
firewall-cmd --zone=public --list-all
firewall-cmd --permanent --zone=public --add-port=222/tcp
firewall-cmd --permanent --zone=public --add-port=22/tcp

0x02 update sshd config

1
sudo vi /etc/ssh/sshd_config

add:

1
2
Port 22
Port 222

0x03 install semanage

It involve with the problem of SELinux when we update ssh ports.

1
2
3
yum provides semanage
yum -y install policycoreutils-python
semanage port -a -t ssh_port_t -p tcp 222

and

1
2
3
systemctl restart sshd
or
reboot

0x04 end

1
2
firewall-cmd --permanent --zone=public --remove-port=22/tcp
firewall-cmd --reload

vi /etc/ssh/sshd_config & remove Port 22

  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2020-2024 Lin