Telnet to port 22: what the SSH-2.0 banner means
Telnet or nc to port 22 shows a line like SSH-2.0-OpenSSH_9.6. That proves an SSH server is reachable, but Telnet cannot log in to it. How to read the result.
You can open a Telnet connection to an SSH port, but you cannot log in through it. It is still one of the quickest ways to check that an SSH server is up and reachable.
Why Telnet cannot log in
Telnet sends plain text over a network virtual terminal. SSH starts with a one-line version exchange in plain text and then switches to binary, encrypted key exchange. A Telnet client cannot take part in that key exchange, so it never reaches a login prompt. Use an SSH client to log in.
What you see
Both sides of an SSH connection send an identification line. An OpenSSH server sends its line as soon as the connection opens, so Telnet shows it straight away:
SSH-2.0-OpenSSH_9.6p1 Ubuntu-3ubuntu13
The format is SSH- followed by the protocol version (2.0), a dash, the server software and version, and an optional comment after a space. A server may send other lines of text before it. OpenSSH does not accept such lines from a client.
If you then type something and press Enter, OpenSSH sees that it is not an SSH identification line, replies Invalid SSH identification string. and closes the connection. If you type nothing, the server closes the connection when its login time limit runs out. In OpenSSH that is LoginGraceTime, 120 seconds by default.
Use it as a port test
- An
SSH-line appears. An SSH server is listening and nothing on the network path is blocking the port. A login problem is further on, in keys, passwords or algorithms. The version in the line also tells you how old the server is, which helps with SSH "no matching key exchange method" and "no matching host key type" errors. - Connection refused. The host answered, but nothing listens on that port. The SSH service is stopped or uses another port.
- No answer, then a timeout. A firewall drops the traffic, the address is wrong, or the host is down.
- It connects, then closes with no line. The server accepted the connection and dropped it, for example because of connection limits. See SSH banner exchange errors, "Connection closed" and "timed out during banner exchange".
- Some other text appears, such as a
login:prompt or an HTTP error. Another service owns that port.
Other tools for the same test
nc -v host.example.com 22connects and shows the same line.- In Windows PowerShell,
Test-NetConnection host.example.com -Port 22reportsTcpTestSucceeded : Truewhen the port is open. It does not show the banner. - The Windows
telnetcommand must be installed as the Telnet Client feature before you can run it.
Related
- SSH banner exchange errors, "Connection closed" and "timed out during banner exchange"
- Connection abort, reset and timed-out errors in SSH and Telnet clients
- SSH: how it works
- Telnet basics
- Telnet "Connection closed by foreign host"
- Can PuTTY or Windows Telnet connect to a mainframe or IBM i?
- Check if a TCP port is open without Telnet: nc, Test-NetConnection, bash