# fahrj/reverse-ssh architecture

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

- Interactive diagram: https://gitdiagram.com/fahrj/reverse-ssh
- Repository: https://github.com/fahrj/reverse-ssh

## Overview

ReverseSSH is a compact SSH server for interactive remote access, command execution, SFTP, and port forwarding, usable in bind or reverse-connection mode. The operator connects with SSH or SFTP; the program parses its mode and either listens for an inbound SSH connection or dials home and creates a forwarded listener, then serves SSH sessions and their requested features. The graph includes the documented forwarding and transfer capabilities, though their internal implementations are only partly shown. Source-level detail is limited to the supplied excerpts; some feature links rely on README documentation.

Main entry points: [`main.go`](https://github.com/fahrj/reverse-ssh/blob/master/main.go) (SSH server), [`ssh_session.go`](https://github.com/fahrj/reverse-ssh/blob/master/ssh_session.go) (Session dispatch), [`core.go`](https://github.com/fahrj/reverse-ssh/blob/master/core.go) (Dial home), [`ssh_session_unix.go`](https://github.com/fahrj/reverse-ssh/blob/master/ssh_session_unix.go) (Unix PTY shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime and SSH"]
  node_parameters["Mode and parameters<br/>[core.go]"]
  node_listener["Bind listener<br/>[core.go]"]
  node_ssh_server["SSH server<br/>[main.go]"]
  node_authentication["Password/key auth<br/>[core.go]"]
end

subgraph group_sessions["Shell Sessions"]
  node_session_handler["Session dispatch<br/>[ssh_session.go]"]
  node_command["Command execution<br/>[ssh_session.go]"]
  node_unix_pty["Unix PTY shell"]
  node_windows_pty["Windows PTY shell"]
end

subgraph group_features["SSH Features"]
  node_sftp["SFTP subsystem<br/>[core.go]"]
  node_local_forward["Local forwarding<br/>[main.go]"]
  node_remote_forward["Remote forwarding<br/>[main.go]"]
  node_forward_handler["Forwarded TCP handler<br/>[main.go]"]
end

subgraph group_reverse["Reverse Connection"]
  node_home_dial["Dial home<br/>[core.go]"]
  node_home_listener["Reverse listener<br/>[core.go]"]
  node_connection_info["Connection metadata<br/>[core.go]"]
end

node_operator(("SSH/SFTP operator"))

node_operator -->|"connects to"| node_listener
node_operator -->|"requests SSH/SFTP"| node_ssh_server
node_parameters -->|"selects bind mode"| node_listener
node_parameters -->|"selects reverse mode"| node_home_dial
node_listener -->|"serves SSH"| node_ssh_server
node_home_dial -->|"opens forwarded listener"| node_home_listener
node_home_listener -->|"serves SSH"| node_ssh_server
node_ssh_server -->|"configures auth"| node_authentication
node_ssh_server -->|"dispatches sessions"| node_session_handler
node_session_handler -->|"runs command"| node_command
node_session_handler -->|"starts PTY"| node_unix_pty
node_session_handler -->|"starts PTY"| node_windows_pty
node_ssh_server -->|"registers subsystem"| node_sftp
node_ssh_server -->|"configures callback"| node_local_forward
node_ssh_server -->|"configures callback"| node_remote_forward
node_ssh_server -->|"registers requests"| node_forward_handler
node_home_dial -->|"sends metadata"| node_connection_info
node_operator -.->|"requests forwarding"| node_local_forward
node_operator -.->|"requests forwarding"| node_remote_forward
node_operator -->|"transfers files"| node_sftp

click node_parameters "https://github.com/fahrj/reverse-ssh/blob/master/core.go"
click node_listener "https://github.com/fahrj/reverse-ssh/blob/master/core.go"
click node_ssh_server "https://github.com/fahrj/reverse-ssh/blob/master/main.go"
click node_authentication "https://github.com/fahrj/reverse-ssh/blob/master/core.go"
click node_session_handler "https://github.com/fahrj/reverse-ssh/blob/master/ssh_session.go"
click node_command "https://github.com/fahrj/reverse-ssh/blob/master/ssh_session.go"
click node_unix_pty "https://github.com/fahrj/reverse-ssh/blob/master/ssh_session_unix.go"
click node_windows_pty "https://github.com/fahrj/reverse-ssh/blob/master/ssh_session_windows.go"
click node_sftp "https://github.com/fahrj/reverse-ssh/blob/master/core.go"
click node_local_forward "https://github.com/fahrj/reverse-ssh/blob/master/main.go"
click node_remote_forward "https://github.com/fahrj/reverse-ssh/blob/master/main.go"
click node_forward_handler "https://github.com/fahrj/reverse-ssh/blob/master/main.go"
click node_home_dial "https://github.com/fahrj/reverse-ssh/blob/master/core.go"
click node_home_listener "https://github.com/fahrj/reverse-ssh/blob/master/core.go"
click node_connection_info "https://github.com/fahrj/reverse-ssh/blob/master/core.go"

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_parameters,node_listener,node_ssh_server,node_authentication toneBlue
class node_session_handler,node_command,node_unix_pty,node_windows_pty toneAmber
class node_sftp,node_local_forward,node_remote_forward,node_forward_handler toneMint
class node_home_dial,node_home_listener,node_connection_info toneRose
class node_operator toneIndigo
```

## Components

### Runtime and SSH

- [Mode and parameters](https://github.com/fahrj/reverse-ssh/blob/master/core.go): `core.go`
- [Bind listener](https://github.com/fahrj/reverse-ssh/blob/master/core.go): `core.go`
- [SSH server](https://github.com/fahrj/reverse-ssh/blob/master/main.go): `main.go`
- [Password/key auth](https://github.com/fahrj/reverse-ssh/blob/master/core.go): `core.go`

### Shell Sessions

- [Session dispatch](https://github.com/fahrj/reverse-ssh/blob/master/ssh_session.go): `ssh_session.go`
- [Command execution](https://github.com/fahrj/reverse-ssh/blob/master/ssh_session.go): `ssh_session.go`
- [Unix PTY shell](https://github.com/fahrj/reverse-ssh/blob/master/ssh_session_unix.go): `ssh_session_unix.go`
- [Windows PTY shell](https://github.com/fahrj/reverse-ssh/blob/master/ssh_session_windows.go): `ssh_session_windows.go`

### SSH Features

- [SFTP subsystem](https://github.com/fahrj/reverse-ssh/blob/master/core.go): `core.go`
- [Local forwarding](https://github.com/fahrj/reverse-ssh/blob/master/main.go): `main.go`
- [Remote forwarding](https://github.com/fahrj/reverse-ssh/blob/master/main.go): `main.go`
- [Forwarded TCP handler](https://github.com/fahrj/reverse-ssh/blob/master/main.go): `main.go`

### Reverse Connection

- [Dial home](https://github.com/fahrj/reverse-ssh/blob/master/core.go): `core.go`
- [Reverse listener](https://github.com/fahrj/reverse-ssh/blob/master/core.go): `core.go`
- [Connection metadata](https://github.com/fahrj/reverse-ssh/blob/master/core.go): `core.go`

### Other components

- **SSH/SFTP operator**

## Connections

- SSH/SFTP operator → Bind listener: connects to (evidence: `Readme.md`)
- SSH/SFTP operator → SSH server: requests SSH/SFTP (evidence: `Readme.md`)
- Mode and parameters → Bind listener: selects bind mode (evidence: `core.go`)
- Mode and parameters → Dial home: selects reverse mode (evidence: `core.go`)
- Bind listener → SSH server: serves SSH (evidence: `core.go`)
- Dial home → Reverse listener: opens forwarded listener (evidence: `core.go`)
- Reverse listener → SSH server: serves SSH (evidence: `core.go`)
- SSH server → Password/key auth: configures auth (evidence: `main.go`)
- SSH server → Session dispatch: dispatches sessions (evidence: `main.go`)
- Session dispatch → Command execution: runs command (evidence: `ssh_session.go`)
- Session dispatch → Unix PTY shell: starts PTY (evidence: `ssh_session.go`)
- Session dispatch → Windows PTY shell: starts PTY (evidence: `ssh_session.go`)
- SSH server → SFTP subsystem: registers subsystem (evidence: `main.go`)
- SSH server → Local forwarding: configures callback (evidence: `main.go`)
- SSH server → Remote forwarding: configures callback (evidence: `main.go`)
- SSH server → Forwarded TCP handler: registers requests (evidence: `main.go`)
- Dial home → Connection metadata: sends metadata (evidence: `core.go`)
- SSH/SFTP operator → Local forwarding: requests forwarding (evidence: `Readme.md`)
- SSH/SFTP operator → Remote forwarding: requests forwarding (evidence: `Readme.md`)
- SSH/SFTP operator → SFTP subsystem: transfers files (evidence: `Readme.md`)
