Changing the standard SSH port in Centos 7

SSH is an application-level network protocol that allows remote control of the operating system and tunneling of TCP connections.

Check what is allowed on the server in the firewall:

[[email protected]]# firewall-cmd --permanent --list-all
public (default)
  services: ssh dhcpv6-client
  masquerade: no
  rich rules:

Open the port on which we want to hang OpenSSH

[[email protected]]# firewall-cmd --permanent --zone=public --add-port=6622/tcp
[[email protected]]# firewall-cmd --reload


[[email protected]]# firewall-cmd --zone=public --list-ports

Editing the sshd_config configuration file

[[email protected]]# nano /etc/ssh/sshd_config
Port 6622

Thus, we changed the standard port 22 to 6622.

At this point, DO NOT restart the SSH service

If you haven’t disabled SELinux, you need to make some changes

[[email protected]]# yum install policycoreutils-python
[[email protected]]# semanage port -a -t ssh_port_t -p tcp 6622

Now you can restart the sshd service

[[email protected]]# systemctl restart sshd

Check the ssh connection on the new port 6622. If everything is ok, close access to the standard port

[[email protected]]# firewall-cmd --permanent --zone=public --remove-service=ssh
[[email protected]]# firewall-cmd --reload