SSH is by default configured to listen to port 22 and only on port 22. You can configure your SSH server to run on other ports, and the same method allows you to configure your SSH server to run and listen on multiple ports.
Running an SSH server on more than one port could be helpful if your SSH server is connected to multiple networks, requiring your SSH server to listen on different ports for the other networks.
Related: How to modify the SSH server port
$ ss -tlnp | grep -E "22|2022" LISTEN 0 128 *:22 *:* LISTEN 0 128 :::22 :::*
SSH service currently runs on port 22, which is expected.
$ sudo vi /etc/ssh/sshd_config
Port 22 Port 2022
Notice the multiple declaration of the Port directive where SSH will listen to all the listed ports.
Make sure the line does not begin with # as it implies the line is commented and will be ignored.
$ sudo ufw allow 2022/tcp # Ubuntu/Debian $ sudo firewall-cmd --add-port=2022/tcp --permanent && sudo firewall-cmd --reload # CentOS / Red Hat success success
It is assumed the default port, 22 is already configured with correct firewall configuration. Add if necessary.
$ sudo semanage port -a -t ssh_port_t -p tcp 2022
semanage can be installed on CentOS or Red Hat systems using the following command:
$ sudo yum install --assumeyes policycoreutils-python
It is assumed the default port, 22 is already configured with correct selinux policy. Add if necessary.
$ sudo systemctl restart sshd
$ ss -tlnp | grep 22 LISTEN 0 128 *:2022 *:* LISTEN 0 128 *:22 *:* LISTEN 0 128 :::2022 :::* LISTEN 0 128 :::22 :::*
Comment anonymously. Login not required.