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:
Connect to the ECS instance by using Virtual Network Computing (VNC).
For more information, see Connection method overview.
NoteIf you cannot connect to the ECS instance by using SSH, you can connect to the instance by using only VNC.
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.Run the following command to query the actual port number used by the sshd process:
netstat -ntlp |grep sshd
NoteIf 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 thesshd_config
configuration file.
Modify the
sshd_config
configuration file.Open the
sshd_config
configuration file.vim /etc/ssh/sshd_config
Press the I key to enter Insert mode.
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.Press the Esc key, enter :wq, and then press the Enter key to save and close the configuration file.
Restart the sshd service.
systemctl restart sshd