我要评分
获取效率
正确性
完整性
易理解

(Optional) Changing the SSH Port

For security and management purposes, you need to change the default port 22 of the SSH service.

  1. Change the default SSH port.
    1. Open the SSH configuration file.
      vi /etc/ssh/sshd_config
    2. Press i to enter the insert mode and change the value of Port (8700 is used as an example).
      Port 8700

    3. Press Esc to exit the insert mode. Type :wq! and press Enter to save and exit the file.
  2. In the SELinux environment, allow the SSH service to use the specified port 8700.
    semanage port -a -t ssh_port_t -p tcp 8700

    If the system displays a message indicating that the semanage command is not installed, run the following command to install it:

    yum provides semanage

    dnf install policycoreutils-python-utils-3.3-8.oe2203sp3.noarch
  3. Enable port 8700 on the firewall.
    firewall-cmd --zone=public --add-port=8700/tcp –-permanent
    firewall-cmd --reload
  4. Restart the SSH service.
    systemctl restart sshd
  5. Verify the SSH port.
    After the port is changed, the original default port 22 cannot be connected using ssh. You must use the -p option in ssh to specify the new port (8700) for connection.
    ssh 192.168.20.150

    ssh -p 8700 192.168.20.150