<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/ssh-handshake-explained-2qlkdmkad" -->

---
title: SSH Handshake Explained | daily.dev
description: A detailed technical breakdown of how the SSH handshake establishes a secure connection, covering version exchange, key exchange initialization, Elliptic Curve...
canonical: https://daily.dev/posts/ssh-handshake-explained-2qlkdmkad
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: SSH Handshake Explained | daily.dev
og:description: A detailed technical breakdown of how the SSH handshake establishes a secure connection, covering version exchange, key exchange initialization, Elliptic Curve...
og:url: https://daily.dev/posts/ssh-handshake-explained-2qlkdmkad
og:image: https://api.daily.dev/og/posts/2qlKDmKad.png
og:image:alt: SSH Handshake Explained
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# SSH Handshake Explained

**[Teleport](https://daily.dev/sources/teleport)** · 9 min read · 0 upvotes · 0 comments

## Summary

A detailed technical breakdown of how the SSH handshake establishes a secure connection, covering version exchange, key exchange initialization, Elliptic Curve Diffie-Hellman initialization and reply, and the generation of new session keys. Explains forward secrecy, exchange hash signing, host key verification against known_hosts, and why separate encryption, integrity, and IV keys are needed for client-to-server and server-to-client communication, referencing the relevant RFC formulas. Uses Teleport's default cryptographic primitives as a working example throughout.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://goteleport.com/blog/ssh-handshake-explained>

## Questions this post answers

### What are the steps involved in an SSH handshake?

An SSH handshake consists of five steps: protocol version exchange, key exchange initialization, Elliptic Curve Diffie-Hellman initialization, Elliptic Curve Diffie-Hellman reply, and generation of new keys. During this process the client and server negotiate cryptographic primitives, derive a shared secret, verify the server's host key, and generate six session keys before sending SSH_MSG_NEWKEYS to switch to encrypted communication.

_Explore more protocol internals like this on daily.dev when deepening your networking and security knowledge._

### Why does SSH generate six separate keys instead of just using the shared secret K?

SSH derives six distinct keys - two encryption keys, two initialization vectors, and two integrity keys - because reusing a single shared secret across different cryptographic purposes can be insecure, as seen with combinations like AES-256-CBC and AES-256-CBC-MAC. Separate client-to-server and server-to-client integrity keys also prevent replay attacks where a captured record is echoed back to its sender.

_Developers comparing cryptographic design choices can track deep dives like this via daily.dev._

### How does SSH prevent man-in-the-middle attacks during the key exchange?

SSH prevents man-in-the-middle attacks by having the server sign an exchange hash with its host private key, which the client verifies using the host public key checked against a local known_hosts database; if the key isn't trusted, the connection terminates. Using SSH certificates instead of raw keys, as Teleport does by default, lets a single trusted Certificate Authority validate many hosts at once.

_Engineers hardening SSH access can keep up with security protocol deep dives on daily.dev._

## Similar posts on daily.dev

- [EP228: How SSH Works](https://daily.dev/posts/ep228-how-ssh-works-8iedgbuir) · ByteByteGo · 1 upvotes · 0 comments
- [Getting started with SSH: Your complete guide to understanding the secure shell](https://daily.dev/posts/getting-started-with-ssh-your-complete-guide-to-understanding-the-secure-shell-kzltkr6dq) · All Things Open · 2 upvotes · 0 comments
- [SSH Essentials: Working with SSH Servers, Clients, and Keys](https://daily.dev/posts/ssh-essentials-working-with-ssh-servers-clients-and-keys-hkehvz7fe) · DigitalOcean Community · 0 upvotes · 0 comments

---

Tags: [#security](https://daily.dev/tags/security), [#cryptography](https://daily.dev/tags/cryptography), [#ssh](https://daily.dev/tags/ssh)

[View this post on daily.dev](https://daily.dev/posts/ssh-handshake-explained-2qlkdmkad)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"SSH Handshake Explained","url":"https://daily.dev/posts/ssh-handshake-explained-2qlkdmkad","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/ssh-handshake-explained-2qlkdmkad"},"datePublished":"2026-08-23T12:22:51.177Z","dateModified":"2026-08-23T12:50:46.543Z","description":"A detailed technical breakdown of how the SSH handshake establishes a secure connection, covering version exchange, key exchange initialization, Elliptic Curve...","image":"https://media.daily.dev/image/upload/s--foaA6JGU--/f_auto/v1722860399/public/Placeholder%2004","thumbnailUrl":"https://media.daily.dev/image/upload/s--foaA6JGU--/f_auto/v1722860399/public/Placeholder%2004","isAccessibleForFree":true,"articleSection":"Teleport","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Teleport","logo":"https://media.daily.dev/image/upload/s--Dw-Bbw6O--/c_limit,w_256/f_auto,q_auto/v1787487494/logos/teleport?_a=BAMAMicg0","url":"https://daily.dev/sources/teleport"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/ssh-handshake-explained-2qlkdmkad","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"security,cryptography,ssh","timeRequired":"PT9M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Teleport","item":"https://daily.dev/sources/teleport"},{"@type":"ListItem","position":3,"name":"SSH Handshake Explained"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/ssh-handshake-explained-2qlkdmkad#faq","mainEntity":[{"@type":"Question","name":"What are the steps involved in an SSH handshake?","acceptedAnswer":{"@type":"Answer","text":"An SSH handshake consists of five steps: protocol version exchange, key exchange initialization, Elliptic Curve Diffie-Hellman initialization, Elliptic Curve Diffie-Hellman reply, and generation of new keys. During this process the client and server negotiate cryptographic primitives, derive a shared secret, verify the server's host key, and generate six session keys before sending SSH_MSG_NEWKEYS to switch to encrypted communication. Explore more protocol internals like this on daily.dev when deepening your networking and security knowledge."}},{"@type":"Question","name":"Why does SSH generate six separate keys instead of just using the shared secret K?","acceptedAnswer":{"@type":"Answer","text":"SSH derives six distinct keys - two encryption keys, two initialization vectors, and two integrity keys - because reusing a single shared secret across different cryptographic purposes can be insecure, as seen with combinations like AES-256-CBC and AES-256-CBC-MAC. Separate client-to-server and server-to-client integrity keys also prevent replay attacks where a captured record is echoed back to its sender. Developers comparing cryptographic design choices can track deep dives like this via daily.dev."}},{"@type":"Question","name":"How does SSH prevent man-in-the-middle attacks during the key exchange?","acceptedAnswer":{"@type":"Answer","text":"SSH prevents man-in-the-middle attacks by having the server sign an exchange hash with its host private key, which the client verifies using the host public key checked against a local known_hosts database; if the key isn't trusted, the connection terminates. Using SSH certificates instead of raw keys, as Teleport does by default, lets a single trusted Certificate Authority validate many hosts at once. Engineers hardening SSH access can keep up with security protocol deep dives on daily.dev."}}]}
```

