Save 10%Pay yearly on any plan. 6% half-yearly, 3% quarterly. Help centreWhatsAppTelegram TeamsOpen a ticket

What Is the SSH Protocol, and How Does It Work?

SSH gives an encrypted, authenticated connection to a remote computer. The steps of a connection in plain words: key exchange, host key, login, and channels.

4 min readBy Daniel

Reviewed by the AmazingRDP technical team

How the SSH protocol works

See SSH at work on a server of your own: a Linux VPS with root access. See Linux VPS from $6.99

SSH, the Secure Shell protocol, is how administrators reach remote computers: an encrypted connection over which you type commands, copy files and forward other traffic. It was written in 1995 to replace Telnet and similar tools, which sent everything, passwords included, as readable text. The version in use everywhere today is SSH-2; its best-known implementation is OpenSSH. This page explains what happens inside a connection.

What SSH guarantees

PropertyMeaning
ConfidentialityNobody on the path can read the traffic
IntegrityNobody can alter it unnoticed
Server authenticationYou can verify that you reached the right machine
User authenticationThe server verifies who you are

A connection, step by step

  1. TCP connection. The client connects to the server, by default on port 22.
  2. Version exchange. Each side sends a line naming its protocol and software version.
  3. Algorithm negotiation. Each side lists the methods it supports for key exchange, encryption and integrity. The first choice both have in common is used.
  4. Key exchange. The two sides compute a shared secret using a method (today usually based on Curve25519, increasingly combined with a quantum-resistant one) that lets them agree on it without ever sending it. Someone recording the whole conversation cannot derive it.
  5. Server proves its identity. The server signs the exchange with its private host key. The client checks the signature against the host key it remembers for this server.
  6. Encryption starts. Session keys are derived from the shared secret; everything from here on is encrypted.
  7. User authentication. Only now, inside the encrypted channel, do you prove who you are.
  8. Channels open. The client asks for what it wants: a shell, a single command, a file transfer, a forwarded port.

The host key and the first-connection question

The first time you connect to a server, the client has no stored key to compare with, and asks:

The authenticity of host '203.0.113.10' can't be established.
ED25519 key fingerprint is SHA256:...
Are you sure you want to continue connecting (yes/no/[fingerprint])?

Answering yes stores the key in ~/.ssh/known_hosts. From then on the client checks it silently. If the key ever differs, the client refuses with a loud warning about a possible "man-in-the-middle attack". After you reinstalled the server that is expected, and you remove the old entry with ssh-keygen -R 203.0.113.10. Otherwise it is exactly the event this check exists to catch, and you should find out why before going on.

How you prove who you are

MethodHow it worksNote
PasswordSent to the server inside the encrypted channelSafe from eavesdroppers, but guessable; servers on the internet are tried constantly
Public keyThe server holds your public key. The client signs a value tied to this session with the private key; the server checks the signatureThe private key never leaves your computer. The recommended method
Keyboard-interactiveThe server asks one or more questionsUsed for one-time codes as a second factor
CertificatesKeys signed by an authority the server trustsFor organisations with many servers and users

Setting up keys: SSH keys on Linux.

Two kinds of cryptography, each for its job

  • Asymmetric cryptography (key pairs) is used at the start: to agree on a secret and to prove identities. It is slow, so it is used only briefly.
  • Symmetric cryptography (one shared key, with ciphers such as ChaCha20 or AES) encrypts the actual traffic. It is fast.
  • Integrity checks on every packet detect any change.

The session keys exist only for the connection and are renegotiated during long sessions. Because they are not derived from the long-term keys, recorded traffic stays unreadable even if a host key is stolen later. This is called forward secrecy.

The three layers

LayerDoes
TransportKey exchange, server authentication, encryption, integrity (steps 2 to 6)
User authenticationVerifies the user (step 7)
ConnectionCarries many logical channels over the one encrypted connection (step 8)

What travels in the channels

  • An interactive shell.
  • A single command: ssh web "uptime".
  • File transfer: SFTP and scp.
  • Local port forwarding: ssh -L 8080:localhost:80 web makes the server's port 80 appear on your own machine, a safe way to reach a service that is not open to the internet.
  • Remote and dynamic forwarding, the latter turning the connection into a SOCKS proxy.
  • Other tools riding on top: Git, rsync, Ansible and remote editing.

SSH and its relatives

SSHTelnetTLS (HTTPS)RDP
EncryptedYesNoYesYes
PurposeRemote command line, files, tunnelsRemote command lineSecuring web and other trafficRemote graphical desktop
Server identity checked byA key you remember from the first contactNothingCertificates issued by authoritiesA certificate

The graphical counterpart is described in how the Remote Desktop Protocol works.

Where the weak points are

The protocol itself has held up for decades. Break-ins through SSH almost always come from elsewhere: guessed passwords, stolen private keys without a passphrase, outdated server software, or a user who answered "yes" to a changed host key. The cure for each is in SSH hardening.

Trying it

ssh -v anna@203.0.113.10

The -v option prints each step described above as it happens: the versions, the chosen algorithms, the host key, the authentication methods tried. Clients for Windows are compared in SSH clients for Windows, with PuTTY step by step. For a server to connect to, see our Linux VPS plans.

Questions

What is SSH?

Secure Shell: a protocol for an encrypted, authenticated connection to a remote computer, used for commands, file transfer and tunnels.

Which port does SSH use?

TCP port 22 by default. Servers can be configured to use another.

How does SSH key authentication work?

The server holds your public key. Your client signs a session-specific value with the private key, and the server verifies the signature. The private key never leaves your computer.

What is an SSH host key?

The server's own key pair, used to prove its identity. Your client remembers it at the first connection and warns if it ever changes.