Summary

  • SSH derives its session identifier from the first key-exchange hash — a value computed from the negotiated transcript, not declared by either side.
  • Rekeying can replace algorithms, traffic keys, initialization vectors, compression and even the server host key while the original session identifier stays put. New protection does not mean a new conversation.
  • Public-key authentication signs the session identifier together with the account, service, method, algorithm and key — blocking cross-session replay, but never granting a shell or a forwarding rule without server-local authorization.

Why a long connection needs more than one set of keys

An SSH session can swap out every lock, every key and even the name on the door, and still insist it is the same room. That stubbornness is not sentiment. It is a hash, computed once at the start, that the protocol refuses to recompute.

Secure remote login has to juggle two kinds of continuity at once. A conversation may run for hours, carry several logical channels and pile up application state. The keys protecting its packets have no business lasting that long.

So the protocol faces a fork. If swapping keys also tore down every higher-layer association, routine rekeying would slam shells shut, stall file transfers and abandon forwarded channels. If swapping keys quietly minted a new identity, an authentication statement made before the change would drift loose from the connection it was meant to authorize.

SSH version 2 answered by cutting its work into layers. RFC 4251 describes a transport protocol that authenticates the server and protects the byte stream, a user-authentication protocol above it, and a connection protocol that multiplexes shells, subsystems and forwarded streams. The split is not decoration. It lets transport protection change while the protocols above keep knowing exactly which conversation they inhabit.

The bridge between those layers is a value the user never picks and the server never announces as a friendly session name.

The session's name is built, not declared

Each side opens key exchange with SSH_MSG_KEXINIT — a packet carrying a random cookie and ordered preference lists for key exchange, server host key, encryption, integrity, compression and more. The winner in each category is the first client-preferred option both sides support under the method's conditions.

Negotiation alone builds no secure channel. The chosen key-exchange method also produces a shared secret K and an exchange hash H. In the original finite-field Diffie–Hellman construction, H covers both protocol identification strings, both raw KEXINIT payloads, the server host key, the two ephemeral exchange values and the shared secret.

That recipe matters. Change a version string, an algorithm offer, the server key or an ephemeral input, and the transcript being hashed is a different transcript. The result is not an assertion such as “session 47.” It is a compact consequence of what the endpoints actually negotiated and computed.

The random cookies add unpredictability, but they hand neither side unilateral naming rights, because both KEXINIT packets go into the hash. The shared secret is not the identifier either. SSH can expose the session identifier without turning it into a credential: holding the identifier reveals nothing about K and grants no ability to compute valid traffic protection.

What the host signature proves — and what it doesn't

The server signs the exchange hash with the host key chosen during negotiation. A successful check shows that the holder of that private host key signed this exchange transcript, and it stops the algorithm negotiation from being silently rewritten in transit.

It does not, by mathematics alone, prove the public key belongs to the hostname the user meant to reach. The client still needs a trust rule: a saved host-key association, a certificate-based system, a verified fingerprint or some other configured method. Accept an unfamiliar key without checking, and you can get a perfectly valid signature from the wrong machine.

Here is the first authority boundary. The exchange hash records protocol evidence. The host signature ties that evidence to one key. The client's trust configuration ties the key to an intended server name. Collapse those three steps into “SSH authenticated the server” and you erase the spot where an operational decision still has to happen.

Only the first hash gets to be the session identifier

RFC 4253 gives H two jobs in the first key exchange. It feeds the derivation of encryption and integrity keys, and it becomes session_id, the unique identifier for that connection. Later exchanges still produce a fresh shared secret and a fresh exchange hash for fresh protection — they simply do not replace session_id.

Rekeying is otherwise free to be drastic. Either party can start it. Algorithms can change. The host key can change. Every key and initialization vector is recalculated, and encryption and compression contexts reset after the new-keys boundary. Yet the server stays the server, the client stays the client, and the session identifier stays fixed.

None of that claims nothing important moved. A new host key may demand a fresh trust evaluation. A weaker negotiated method may be unacceptable. A failed rekey can end the connection. The invariant says something narrower: successful transport renewal does not manufacture a new higher-layer conversation.

Nor does the identifier survive a replacement connection. Reconnect after TCP loss and the new initial exchange produces a new H. Applications may restore files, terminals or jobs by their own machinery, but they cannot call the new transport the same SSH session just because the user and host names match.

User authentication signs the connection into the request

The fixed value earns its keep when the client proves possession of a user private key. RFC 4252 does not define that proof as a signature over the username alone. The signed byte sequence starts with the session identifier and continues through the exact SSH_MSG_USERAUTH_REQUEST: message number, user name, requested service, method name, a boolean, public-key algorithm and public-key blob.

An attacker who records that signature cannot drop it unchanged into another connection. The other connection has a different first exchange hash, hence a different session identifier. Alter the account, service, method, algorithm or key, and the signed statement changes too.

The design keeps three questions apart. Does the signature verify for the submitted key? Is that key acceptable for this claimed account? Has the server's authentication policy — perhaps demanding another method — been satisfied? One valid cryptographic calculation answers none of them on its own.

Host-based authentication reuses the same connection-binding pattern with extra client-host and client-user fields. Again the signature proves possession in the context the request names. The server must still decide whether the host key belongs to the named client, and whether that host and user may log in.

A successful login is not a blank cheque

Once the server sends SSH_MSG_USERAUTH_SUCCESS, the requested service can start. It is tempting to read that packet as a general grant. The architecture refuses the shortcut.

Local policy picks the acceptable authentication methods and combinations for each user. It also governs everything after: starting a shell, invoking a subsystem, opening a port forward, accepting an agent-forwarding request, reaching a particular destination. Some of those decisions cannot even be made during authentication, because the client has not yet said which channel it will request.

The session identifier therefore supplies binding, not entitlement. It lets a higher layer say, “this proof belongs to this protected conversation.” It does not let that layer say, “every future action in the conversation is approved.” A stable context can carry many separately authorized operations.

The same distinction bounds audit claims. A log holding the session identifier and a successful public-key method can tie an authentication exchange to a transport. Without channel and policy records, it cannot prove which commands ran, which forwarding requests were allowed, or what the application data meant.

The algorithms aged; the boundary held

The 2006 documents named algorithms that did not all stay suitable. None of that required redesigning the cross-layer binding.

RFC 8332 added RSA signatures using SHA-256 and SHA-512 for both server and client authentication. Existing RSA key material could keep its ssh-rsa key format while a different algorithm name selected the stronger signature procedure. Key bytes, signature algorithm and the statement being signed stayed separate objects.

RFC 9142 later revised implementation recommendations across SSH key-exchange methods, moving away from SHA-1-based choices and requiring stronger alternatives in its recommendation set. The registry and the recommendations could evolve because negotiation carried named algorithms. The session rule held: the first accepted exchange fixes the connection's binding context; later key exchanges renew protection inside it.

Do not mistake that continuity for approval of obsolete methods. A session identifier built by a weak or wrongly trusted exchange binds later authentication faithfully to a weak or wrongly trusted beginning. Binding preserves context; it does not repair the quality of the context.

Evidence must remember which layer produced it

Five records may all get called “SSH identity” in a sloppy dashboard: host name, host key, exchange hash, session identifier and user key. They answer different questions.

The host name is the intended destination label. The host key is a cryptographic principal that must be tied to that label. An exchange hash describes one negotiated key exchange. Its first value becomes a connection-scoped identifier. A user key backs a method of proving possession for one account-and-service request. None substitutes for the server's authorization rule or the application's record of work done.

The standards establish these semantics and their algorithm history, not the behaviour of every deployment. They do not prove a particular client checks host keys, that a server rotates keys on schedule, that SHA-1 has vanished, that local policy is sensible, or that a successful login caused any specific command to run.

SSH's durable move was modest but exact. It let the keys age without letting the conversation forget its beginning. The first hash never became a universal identity. It became the evidence boundary that later proofs could name — and the reason a session can change every key it owns without ever changing its story about who it is.