SSH and Workbench connection failure from incorrect port
Updated at:
Copy as MD
Problem description
You cannot connect to an ECS instance using SSH or Workbench. An instance health diagnostic report indicates that the sshd process is listening on an address and port that do not match those specified in the configuration file.
Cause
You cannot connect to the ECS instance because the sshd process is listening on an address and port that are inconsistent with its configuration file, /etc/ssh/sshd_config.
Solution
To resolve this issue, modify the listening address and port in the SSH service configuration.
- Connect to the ECS instance using VNC.
For more information, see Choose a connection method.Note If you cannot log on to the ECS instance using SSH, you must connect with VNC.
- Check whether the port number in the
sshd_configconfiguration file matches the port the sshd process is listening on.If they do not match, proceed to Step 3 to modify the
sshd_configconfiguration file.- Check the port number configured in
sshd_config:sshd -TThe following output shows that the configured port is 23.[xxx@iZbpxxx ~]# sshd -T port 23 addressfamily inet listenaddress 0.0.0.0:23 usepam yes logingracetime 120 x11displayoffset 10 x11maxdisplays 1000 maxauthtries 6 maxsessions 10 clientaliveinterval 0 clientalivecountmax 3 streamlocalbindmask 0177 permitrootlogin yes ignorerhosts yes ignoreuserknownhosts no - Check the port on which the sshd process is listening:
netstat -ntlp |grep sshdNote If the preceding command fails, runss -tlnp | grep sshd.The following output shows the sshd process is listening on port 22. Because this differs from the configured port (23), proceed to Step 3 to modify thesshd_configconfiguration file.[root@rhel8xxx ]# netstat -ntlp |grep sshd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 5091/sshd tcp6 0 0 :::22 :::* LISTEN 5091/sshd
- Check the port number configured in
- Modify the
sshd_configconfiguration file.- Open the
sshd_configconfiguration file.vim /etc/ssh/sshd_config - Press i to enter Insert mode.
- Modify the port number in the
sshd_configconfiguration file to match the port the sshd process is listening on.The port number in thesshd_configconfiguration file must match the port the sshd process is listening on. In this example, change the linePort 23to Port 22.#Port 22 Port 23 #AddressFamily any #ListenAddress 0.0.0.0 #ListenAddress :: HostKey /etc/ssh/ssh_host_rsa_key HostKey /etc/ssh/ssh_host_ecdsa_key HostKey /etc/ssh/ssh_host_ed25519_key - Press Esc, enter :wq, and then press Enter to save the changes and exit.
- Open the
- Restart the sshd service.
systemctl restart sshd
Is this page helpful?