All Products
Search
Document Center

:What do I do if I cannot connect to an ECS instance due to an sshd configuration error?

Last Updated:Sep 02, 2024

This topic describes the cause of and solution to the issue that you cannot connect to an Elastic Compute Service (ECS) instance due to an sshd configuration error.

Problem description

After you modify the sshd configuration file and restart the ECS instance, you cannot use Workbench or a third-party remote connection tool, such as PuTTY, Xshell, and SecureCRT, to connect to the ECS instance.

Cause

The /etc/ssh/sshd_config configuration file contains errors. The sshd service fails to start due to the errors. As a result, you cannot connect to the ECS instance over SSH.

Solution

Connect to the ECS instance by using Virtual Network Computing (VNC), check the sshd configuration file for errors, correct the errors (if any), and then restart the sshd service.

  1. Connect to the ECS instance by using VNC.

    For more information, see Connect to an instance by using VNC.

  2. Run the following command to identify the path in which the sshd configuration file is stored:

    which sshd

    The following command output indicates that the sshd configuration file is stored in the /usr/sbin/sshd path.

    image

  3. Run the following command to run the sshd service in test mode to check whether errors exist in the sshd configuration file.

    Important

    Each time you modify the sshd configuration file, we recommend that you run the following command to check whether errors exist in the configuration file before you restart the ECS instance. This prevents the preceding issue from occurring.

    sudo /usr/sbin/sshd -t
    • If sshd is correctly configured, no information is returned.

    • If sshd is incorrectly configured, information is returned. The following command output indicates that the parameter value on Line 144 of the /etc/ssh/sshd_config configuration file is set to an unsupported value of no1 and must be modified.

      image

  4. Modify the /etc/ssh/sshd_config configuration file.

    1. Run the following command to open the /etc/ssh/sshd_config configuration file:

      sudo vim /etc/ssh/sshd_config
    2. Press the I key to enter Insert mode, find the line that contains an error based on the preceding command output, and correct the error. For example, set the value of the UseDNS parameter on Line 144 to no.

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

  5. Rerun the sudo /usr/sbin/sshd -t command to check whether the error is corrected. If the error is corrected, no information is returned, as shown in the following figure.

    image

  6. Restart the sshd service for the change to take effect.

    sudo systemctl restart sshd.service
    Note

    If an error occurs when you run the systemctl command, troubleshoot the error as described in What do I do if an error occurs when I run the systemctl command on a Linux instance?