All Products
Search
Document Center

Elastic Compute Service:What do I do if I cannot connect to an ECS instance by using SSH or Workbench due to incorrect port configurations?

Last Updated:Sep 09, 2024

Problem description

You cannot connect to an Elastic Compute Service (ECS) instance by using SSH or Workbench. The diagnostic report generated by the instance health diagnostics feature indicates that the sshd process of the ECS instance listens on an address and port that are different from the address and port that you configured for the sshd process to listen on. As a result, SSH connections cannot be established by using the expected address and port.

Cause

The /etc/ssh/sshd_config configuration file of the sshd process does not contain the address and port that the process listens on. As a result, you cannot connect to the ECS instance.

Solution

To resolve the preceding issue, perform the following steps to change the address and port that the sshd process listens on based on your business requirements:

  1. Connect to the ECS instance by using Virtual Network Computing (VNC).

    For more information, see Connection method overview.

    Note

    If you cannot connect to the ECS instance by using SSH, you can connect to the instance by using only VNC.

  2. Check whether the port number in the sshd_config configuration file is the same as the actual port number used by the sshd process.

    If the port numbers are different, proceed to Step 3 to modify the sshd_config configuration file.

    • Run the following command to view the port number in the sshd_config configuration file:

      sshd -T

      The command output shown in the following figure indicates that the port number in the sshd_config configuration file is 23. 查看sshd配置

    • Run the following command to query the actual port number used by the sshd process:

      netstat -ntlp |grep sshd
      Note

      If the preceding command cannot be run, run the ss -tlnp | grep sshd command.

      The command output shown in the following figure indicates that the actual port number used by the sshd process is 22, which is different from port number 23 in the sshd_config configuration file. In this case, proceed to Step 3 to modify the sshd_config configuration file.查看sshd进程实际端口

  3. Modify the sshd_config configuration file.

    1. Open the sshd_config configuration file.

      vim /etc/ssh/sshd_config
    2. Press the I key to enter Insert mode.

    3. Change the port number in the sshd_config configuration file based on your business requirements.

      Make sure that the port number in the sshd_config configuration file is the same as the actual port number used by the sshd process. In this example, Port 23 must be deleted from the configuration file.删除错误端口

    4. Press the Esc key, enter :wq, and then press the Enter key to save and close the configuration file.

  4. Restart the sshd service.

    systemctl restart sshd