This topic describes the cause of and solution for a remote connection failure to an Elastic Compute Service (ECS) instance due to an sshd configuration error.
Symptoms
After you modify the sshd configuration file and restart the instance, you cannot use Workbench or a third-party remote connection tool, such as PuTTY, XShell, or SecureCRT, to connect to the instance.
Cause
The /etc/ssh/sshd_config file contains configuration errors. These errors prevent the sshd service from starting. As a result, you cannot connect to the ECS instance over the Secure Shell (SSH) protocol.
Solution
Connect to the ECS instance using Virtual Network Computing (VNC). Find and correct the errors in the sshd configuration, and then restart the sshd service.
Connect to the ECS instance using VNC.
For more information, see Connect to an instance using VNC.
Run the following command to find the path of the sshd executable.
which sshdThe following output indicates that the sshd executable is located at
/usr/sbin/sshd.
Run the following command to start sshd in test mode and check the configuration file for errors.
ImportantAfter you modify the sshd configuration file, run the following command to check the file for errors before you restart the instance. This helps prevent the issue described in this topic.
sudo /usr/sbin/sshd -tIf no information is returned, the sshd configuration is correct.
If information is returned, the sshd configuration is incorrect. For example, the following output indicates that the parameter on line 144 of the
/etc/ssh/sshd_configfile is set to "no1". This is an unsupported value that you must change.
Modify the /etc/ssh/sshd_config configuration file.
Open the
/etc/ssh/sshd_configconfiguration file.sudo vim /etc/ssh/sshd_configPress the
ikey to enter Insert mode. Based on the error message, find the incorrect line and fix it. For example, on line 144, change the value of the UseDNS parameter to no.UseDNS noPress the
Esckey, enter:wq!, and then press Enter to save the changes and exit the editor.
Rerun the
sudo /usr/sbin/sshd -tcommand to confirm that the configuration is correct. If no information is returned, the error is fixed, as shown in the following figure.
Restart the sshd service for the changes to take effect.
sudo systemctl restart sshd.serviceNoteIf an error occurs when you run the systemctl command, see What do I do if an error occurs when I run the systemctl command on a Linux instance?