Cannot ssh my ubuntu server. "kex_exchange_identification: banner line contains invalid characters"
Asked Answered
S

3

7

When I wanna use VScode remote SSH to my server, the following error is prompted:

... ... kex_exchange_identification: banner line contains invalid characters ... ...

In the beginning, I thought it's an error of my VSCode, but I tried the simplest SSH command in PowerShell, it still happened.

Here is some log:

(base) PS C:\Users\37097> ssh [email protected] -p 1260 -v                                           OpenSSH_8.2p1, OpenSSL 1.1.1f  31 Mar 2020
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to 114.213.208.99 [114.213.208.99] port 1260.
debug1: Connection established.
debug1: identity file /c/Users/37097/.ssh/id_rsa type -1
debug1: identity file /c/Users/37097/.ssh/id_rsa-cert type -1
debug1: identity file /c/Users/37097/.ssh/id_dsa type -1
debug1: identity file /c/Users/37097/.ssh/id_dsa-cert type -1
debug1: identity file /c/Users/37097/.ssh/id_ecdsa type -1
debug1: identity file /c/Users/37097/.ssh/id_ecdsa-cert type -1
debug1: identity file /c/Users/37097/.ssh/id_ecdsa_sk type -1
debug1: identity file /c/Users/37097/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /c/Users/37097/.ssh/id_ed25519 type -1
debug1: identity file /c/Users/37097/.ssh/id_ed25519-cert type -1
debug1: identity file /c/Users/37097/.ssh/id_ed25519_sk type -1
debug1: identity file /c/Users/37097/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /c/Users/37097/.ssh/id_xmss type -1
debug1: identity file /c/Users/37097/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.2
kex_exchange_identification: banner line contains invalid characters

I tried it even in another ubuntu machine, but have the same problem.

And I tried to google it for few days, but none of it can solve my problem.

Sweeney answered 18/3, 2021 at 5:51 Comment(2)
It's likely that port doesn't contain a real SSH server and you're finding some other server instead.Seclusive
@Seclusive God, it's really a stupid MISTAKE I made! This port is my 3389 port, I check my server's SSH port and find that I did type the wrong port, you are absolutely right! Thanks for your answer.Sweeney
B
12

i see this is without reply, hope you could fix it meanwhile.

For anyone else searching for

kex_exchange_identification: banner line contains invalid characters

note that ssh reports this error when connecting to a webserver (https) by mistake instead of a sshd.

Check that sshd is listening on the host/port your are connecting to, e.g. using netstat -anp

Beaune answered 4/1, 2022 at 22:23 Comment(1)
You saved my time with this. I was connection via https port instead of sshd portLamartine
E
7

When an SSH client connects to an SSH server, the SSH server process begins by sending a version string to the client in cleartext. You can see it by using "nc":

$ nc localhost 22
SSH-2.0-OpenSSH_8.6

"kex_exchange_identification" means the client has just connected to the server and is waiting to receive this version string. The error "banner line contains invalid characters" means the client received something from the server that wasn't a valid SSH version string.

As a practical matter, the problem is likely to be that the SSH client connected to something that's not an SSH server. As noted in the other answer, connecting to an HTTPS server with an SSH client will produce this error:

$ ssh -p https google.com
kex_exchange_identification: banner line contains invalid characters

The root cause could be one of three things:

  1. The SSH client connected to the wrong hostname/IP address and/or port.
  2. The service isn't supposed to be accessed through an SSH client.
  3. Something is misconfigured or malfunctioning on the server.
Escapement answered 10/12, 2022 at 15:50 Comment(0)
C
-9

In my case, I just first execute: git pull, then execute git push, then everything got ok.

Caplin answered 13/4, 2023 at 2:31 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Hailee

© 2022 - 2024 — McMap. All rights reserved.