# openssh/openssh-portable architecture

> Architecture diagram of the GitHub repository openssh/openssh-portable, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/openssh/openssh-portable
- Repository: https://github.com/openssh/openssh-portable

## Overview

Portable OpenSSH implements SSHv2 for remote login, command execution and file transfer, with client/server programs and supporting key and agent tools. The principal workflow is a user invoking ssh, establishing an SSH connection to sshd, authenticating, then using a remote session; SCP and SFTP provide file-transfer capabilities. The graph also preserves documented supporting tools and major protocol/security layers. README relationships are documented; links not established by the README or excerpts are omitted. Server internals and several tool integrations were not sampled.

Main entry points: [`ssh.c`](https://github.com/openssh/openssh-portable/blob/master/ssh.c) (SSH client), [`sshd.c`](https://github.com/openssh/openssh-portable/blob/master/sshd.c) (SSH server), [`clientloop.c`](https://github.com/openssh/openssh-portable/blob/master/clientloop.c) (Interactive client loop), [`sftp.c`](https://github.com/openssh/openssh-portable/blob/master/sftp.c) (SFTP client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_tools["User tools"]
  node_ssh["SSH client<br/>[ssh.c]"]
  node_scp["SCP transfer<br/>[scp.c]"]
  node_sftp["SFTP client<br/>[sftp.c]"]
  node_keygen["Key generation<br/>[ssh-keygen.c]"]
  node_keyscan["Host key scan<br/>[ssh-keyscan.c]"]
  node_agent["Key agent<br/>[ssh-agent.c]"]
  node_sftpclient["SFTP protocol client<br/>[sftp-client.c]"]
end

subgraph group_connection["SSH connection"]
  node_clientconnect["Client connection<br/>[sshconnect.c]"]
  node_clientauth["Client authentication<br/>[sshconnect2.c]"]
  node_clientloop["Interactive client loop<br/>[clientloop.c]"]
  node_transport["Packet transport<br/>[packet.c]"]
  node_channels["SSH channels<br/>[channels.c]"]
  node_configuration["Client configuration<br/>[readconf.c]"]
end

subgraph group_security["Identity and security"]
  node_keyexchange["Key exchange<br/>[kex.c]"]
  node_keyfiles["Key files<br/>[sshkey.c]"]
  node_authpolicy["Authentication options<br/>[auth-options.h]"]
  node_hostkeys["Known hosts<br/>[hostfile.h]"]
end

subgraph group_server["Server services"]
  node_server["SSH server<br/>[sshd.c]"]
  node_serverauth["Server authentication<br/>[sshd-auth.c]"]
  node_serverconfig["Server configuration<br/>[servconf.c]"]
  node_session["Remote session<br/>[session.c]"]
  node_sftpserver["SFTP server<br/>[sftp-server.c]"]
end

subgraph group_shared["Shared runtime"]
  node_buffers["SSH buffers<br/>[sshbuf.h]"]
  node_io["Reliable I/O<br/>[atomicio.h]"]
  node_logging["Logging and errors<br/>[log.h]"]
end

node_user(("User"))

node_user -->|"invokes"| node_ssh
node_user -->|"invokes"| node_scp
node_user -->|"invokes"| node_sftp
node_user -->|"invokes"| node_keygen
node_user -->|"invokes"| node_keyscan
node_user -->|"invokes"| node_agent
node_ssh -->|"remote login"| node_server
node_ssh -->|"remote execution"| node_server
node_scp -->|"file transfer"| node_server
node_sftp -->|"file transfer"| node_server
node_ssh -.->|"connects through"| node_clientconnect
node_ssh -.->|"authenticates through"| node_clientauth
node_ssh -.->|"runs loop"| node_clientloop
node_clientconnect -.->|"uses transport"| node_transport
node_clientauth -.->|"negotiates keys"| node_keyexchange
node_server -.->|"authenticates via"| node_serverauth
node_server -.->|"loads configuration"| node_serverconfig
node_server -.->|"serves sessions"| node_session
node_sftp -.->|"uses protocol client"| node_sftpclient
node_sftpclient -.->|"transfers files"| node_sftpserver
node_clientloop -->|"handles channels"| node_channels
node_clientloop -->|"checks host keys"| node_hostkeys
node_clientloop -->|"flushes output"| node_io
node_sftpclient -->|"parses messages"| node_buffers
node_serverauth -.->|"applies options"| node_authpolicy
node_clientauth -.->|"uses keys"| node_keyfiles
node_ssh -.->|"reads settings"| node_configuration

click node_ssh "https://github.com/openssh/openssh-portable/blob/master/ssh.c"
click node_scp "https://github.com/openssh/openssh-portable/blob/master/scp.c"
click node_sftp "https://github.com/openssh/openssh-portable/blob/master/sftp.c"
click node_keygen "https://github.com/openssh/openssh-portable/blob/master/ssh-keygen.c"
click node_keyscan "https://github.com/openssh/openssh-portable/blob/master/ssh-keyscan.c"
click node_agent "https://github.com/openssh/openssh-portable/blob/master/ssh-agent.c"
click node_clientconnect "https://github.com/openssh/openssh-portable/blob/master/sshconnect.c"
click node_clientauth "https://github.com/openssh/openssh-portable/blob/master/sshconnect2.c"
click node_clientloop "https://github.com/openssh/openssh-portable/blob/master/clientloop.c"
click node_server "https://github.com/openssh/openssh-portable/blob/master/sshd.c"
click node_serverauth "https://github.com/openssh/openssh-portable/blob/master/sshd-auth.c"
click node_serverconfig "https://github.com/openssh/openssh-portable/blob/master/servconf.c"
click node_session "https://github.com/openssh/openssh-portable/blob/master/session.c"
click node_sftpserver "https://github.com/openssh/openssh-portable/blob/master/sftp-server.c"
click node_transport "https://github.com/openssh/openssh-portable/blob/master/packet.c"
click node_keyexchange "https://github.com/openssh/openssh-portable/blob/master/kex.c"
click node_keyfiles "https://github.com/openssh/openssh-portable/blob/master/sshkey.c"
click node_authpolicy "https://github.com/openssh/openssh-portable/blob/master/auth-options.h"
click node_hostkeys "https://github.com/openssh/openssh-portable/blob/master/hostfile.h"
click node_channels "https://github.com/openssh/openssh-portable/blob/master/channels.c"
click node_sftpclient "https://github.com/openssh/openssh-portable/blob/master/sftp-client.c"
click node_buffers "https://github.com/openssh/openssh-portable/blob/master/sshbuf.h"
click node_io "https://github.com/openssh/openssh-portable/blob/master/atomicio.h"
click node_logging "https://github.com/openssh/openssh-portable/blob/master/log.h"
click node_configuration "https://github.com/openssh/openssh-portable/blob/master/readconf.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_ssh,node_scp,node_sftp,node_keygen,node_keyscan,node_agent,node_sftpclient,node_user toneBlue
class node_clientconnect,node_clientauth,node_clientloop,node_transport,node_channels,node_configuration toneAmber
class node_keyexchange,node_keyfiles,node_authpolicy,node_hostkeys toneMint
class node_server,node_serverauth,node_serverconfig,node_session,node_sftpserver toneRose
class node_buffers,node_io,node_logging toneIndigo
```

## Components

### User tools

- [SSH client](https://github.com/openssh/openssh-portable/blob/master/ssh.c): `ssh.c`
- [SCP transfer](https://github.com/openssh/openssh-portable/blob/master/scp.c): `scp.c`
- [SFTP client](https://github.com/openssh/openssh-portable/blob/master/sftp.c): `sftp.c`
- [Key generation](https://github.com/openssh/openssh-portable/blob/master/ssh-keygen.c): `ssh-keygen.c`
- [Host key scan](https://github.com/openssh/openssh-portable/blob/master/ssh-keyscan.c): `ssh-keyscan.c`
- [Key agent](https://github.com/openssh/openssh-portable/blob/master/ssh-agent.c): `ssh-agent.c`
- [SFTP protocol client](https://github.com/openssh/openssh-portable/blob/master/sftp-client.c): `sftp-client.c`

### SSH connection

- [Client connection](https://github.com/openssh/openssh-portable/blob/master/sshconnect.c): `sshconnect.c`
- [Client authentication](https://github.com/openssh/openssh-portable/blob/master/sshconnect2.c): `sshconnect2.c`
- [Interactive client loop](https://github.com/openssh/openssh-portable/blob/master/clientloop.c): `clientloop.c`
- [Packet transport](https://github.com/openssh/openssh-portable/blob/master/packet.c): `packet.c`
- [SSH channels](https://github.com/openssh/openssh-portable/blob/master/channels.c): `channels.c`
- [Client configuration](https://github.com/openssh/openssh-portable/blob/master/readconf.c): `readconf.c`

### Identity and security

- [Key exchange](https://github.com/openssh/openssh-portable/blob/master/kex.c): `kex.c`
- [Key files](https://github.com/openssh/openssh-portable/blob/master/sshkey.c): `sshkey.c`
- [Authentication options](https://github.com/openssh/openssh-portable/blob/master/auth-options.h): `auth-options.h`
- [Known hosts](https://github.com/openssh/openssh-portable/blob/master/hostfile.h): `hostfile.h`

### Server services

- [SSH server](https://github.com/openssh/openssh-portable/blob/master/sshd.c): `sshd.c`
- [Server authentication](https://github.com/openssh/openssh-portable/blob/master/sshd-auth.c): `sshd-auth.c`
- [Server configuration](https://github.com/openssh/openssh-portable/blob/master/servconf.c): `servconf.c`
- [Remote session](https://github.com/openssh/openssh-portable/blob/master/session.c): `session.c`
- [SFTP server](https://github.com/openssh/openssh-portable/blob/master/sftp-server.c): `sftp-server.c`

### Shared runtime

- [SSH buffers](https://github.com/openssh/openssh-portable/blob/master/sshbuf.h): `sshbuf.h`
- [Reliable I/O](https://github.com/openssh/openssh-portable/blob/master/atomicio.h): `atomicio.h`
- [Logging and errors](https://github.com/openssh/openssh-portable/blob/master/log.h): `log.h`

### Other components

- **User**

## Connections

- User → SSH client: invokes (evidence: `README`)
- User → SCP transfer: invokes (evidence: `README`)
- User → SFTP client: invokes (evidence: `README`)
- User → Key generation: invokes (evidence: `README`)
- User → Host key scan: invokes (evidence: `README`)
- User → Key agent: invokes (evidence: `README`)
- SSH client → SSH server: remote login (evidence: `README`)
- SSH client → SSH server: remote execution (evidence: `README`)
- SCP transfer → SSH server: file transfer (evidence: `README`)
- SFTP client → SSH server: file transfer (evidence: `README`)
- SSH client → Client connection: connects through
- SSH client → Client authentication: authenticates through
- SSH client → Interactive client loop: runs loop
- Client connection → Packet transport: uses transport
- Client authentication → Key exchange: negotiates keys
- SSH server → Server authentication: authenticates via
- SSH server → Server configuration: loads configuration
- SSH server → Remote session: serves sessions
- SFTP client → SFTP protocol client: uses protocol client
- SFTP protocol client → SFTP server: transfers files
- Interactive client loop → SSH channels: handles channels (evidence: `clientloop.c`)
- Interactive client loop → Known hosts: checks host keys (evidence: `clientloop.c`)
- Interactive client loop → Reliable I/O: flushes output (evidence: `clientloop.c`)
- SFTP protocol client → SSH buffers: parses messages (evidence: `sftp-client.c`)
- Server authentication → Authentication options: applies options
- Client authentication → Key files: uses keys
- SSH client → Client configuration: reads settings
