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.
Connect to the ECS instance by using VNC.
For more information, see Connect to an instance by using VNC.
Run the following command to identify the path in which the sshd configuration file is stored:
which sshdThe following command output indicates that the sshd configuration file is stored in the
/usr/sbin/sshdpath.
Run the following command to run the sshd service in test mode to check whether errors exist in the sshd configuration file.
ImportantEach 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 -tIf 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_configconfiguration file is set to an unsupported value of no1 and must be modified.
Modify the /etc/ssh/sshd_config configuration file.
Run the following command to open the
/etc/ssh/sshd_configconfiguration file:sudo vim /etc/ssh/sshd_configPress the
Ikey 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 noPress the
Esckey, enter:wq, and then press the Enter key to save and close the configuration file.
Rerun the
sudo /usr/sbin/sshd -tcommand to check whether the error is corrected. If the error is corrected, no information is returned, as shown in the following figure.
Restart the sshd service for the change to take effect.
sudo systemctl restart sshd.serviceNoteIf 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?