CentOS Stream 9 uses systemd by default to manage services, including sshd. To change the SSH port, you will need to make a few changes to the sshd configuration file.

Here are the steps you can follow to change the SSH port in CentOS 9 Stream:

  • Log in to the console using an account with administrative privileges (such as root).
    Open the sshd configuration file using a text editor. In CentOS 9 Stream, the sshd configuration file is called sshd_config. Run the following command:

vi /etc/ssh/sshd_config

  • Find the line with the #Port 22 parameter (commented out with "#" by default). Remove the "#" character and change the port to the desired value. For example, to change the port to 2222, the string should look like this:

Port 2222

  • Save the changes and close the configuration file.
    Restart the sshd service to apply the changes:

systemctl restart sshd

If you have SELinux enabled, it should also be allowed to use port 2222

semanage port -a -t ssh_port_t -p tcp 2222

You will also need to configure firewall rules to allow incoming connections on this port. The CentOS 9 Stream defaults to firewalld, the firewall management tool.
firewall-cmd --permanent --add-port=2222/tcp

Restart firewalld to apply the changes:

systemctl restart firewalld

Port 2222 should then be open in the firewalld firewall.

Verify that port 2222 is open by running the command:

firewall-cmd --list-ports

Incoming connections on port 2222 must now be allowed in the CentOS Stream 9 firewall. Make sure that your application or service that you are trying to use through port 2222 is configured appropriately to accept connections on that port.

Comments:
There are no comments for this post yet.
Log in to leave a comment.