ssh remote login error: kex_exchange_identification: Connection closed by remote host

Basic Information

System: MacOS Catalina 10.15.7

Error message:

An error is reported when the terminal logs in to the remote server :

kex_exchange_identification: Connection closed by remote host

copy

However, the one-key login or VNC login of the service provider is normal.

solution

First use the following command to debug the login process in order to locate the problem:

ssh -v <username>@<password>

copy

If you can find a large number of prompts from the information returned at this time point to:

debug1: identify file /Users/<ComputerName>/.ssh XXXXXX

copy

Basically, it can be determined that the problem occurs in the configuration of the machine.

At this time, you need to open Finder, and then access the path through the file

MacOS——Finder——【command+shift+G】
~/.ssh

copy

Find the known_hosts file, clear it, and access the server host again through the terminal.

Sure enough, the problem was solved smoothly, but what is this known_hosts caught my attention, so I checked it out, and wrote it down here together with the ssh login.

SSH key login

1. After receiving the login request from the local machine, the remote host will send its public key to the local machine;

2. The local machine uses this public key to encrypt the password and sends it back to the remote host;

3. The remote host decrypts the login password with its own private key, and if the password is correct, it agrees to log in.

When you log in to a remote host through ssh from a MacOS terminal for the first time, you will be prompted:

The authenticity of <hostname>'XXX.XXX.XXX.XXX' can't be established.
RSA key fingerprint is XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX
Are you sure you want to continue connecting (yes/no)?

copy

The meaning here is that the local machine cannot confirm the authenticity of the remote host, and the user needs to judge whether to trust the incoming RSA Key FingerPrint. After typing yes, it will prompt:

Warning: Permanently added 'XXXX, XXX.XXX.XXX.XXX'(RSA)to the list of known hosts.

copy

Then enter the remote host password to log in normally.

At this time, it means that the local machine has accepted the remote host, and this public key will be saved in /.ssh/known_hosts for later verification.

ssh part reference blog: https://www.cnblogs.com/wangjiyong/p/5210618.html

Sources of solution inspiration:

Know the question: https://www.zhihu.com/question/20023544

Guess you like

Origin blog.csdn.net/Goals1989/article/details/129195446