Skip to main content
RunBook Academy

LinuxXXVI · SSHArchitecture

SSH architecture - how Secure Shell actually works

Foundation⏱ ~10 minsshsshd

What you'll learn

  • Describe the SSH protocol layers and what each does
  • Explain how SSH authenticates the host and the user
  • Understand channels and what flows over an SSH connection
  • Recognise SSH versions and their differences

Prerequisites

Verified against Ubuntu 24.04 LTS · Debian 12 (Bookworm) · RHEL 9.x · Rocky Linux 9.x · AlmaLinux 9.x · Linux kernel 6.1 LTS / 6.6 LTS · systemd 255+ · OpenSSH 8.7p1 (RHEL 9) / 9.6p1 (Ubuntu 24.04) · nftables 1.0.x · chrony 4.x · Pacemaker 2.1.x · Corosync 3.1.x · 2026-08-09

Not yet marked complete on this device.

SSH (Secure Shell) is the standard tool for remote access on Linux. It provides a confidential, integrity-protected channel between two hosts, with mutual authentication. This lesson is about how SSH actually works - the protocol layers, the cryptography, and the channel model.

SSH is not TLS, and it is not built on X.509. It has its own key format, its own certificate format, and its own trust model based on known_hosts rather than a CA bundle. Nothing in this part depends on the PKI material in Part LXXI; read that part for the web/TLS side, but do not expect the concepts to map across one-for-one. They deliberately do not.

The protocol layers

SSH has three layers:

  1. Transport layer (SSH-TRANS): provides the encrypted channel. Handles key exchange, server authentication, and symmetric encryption.
  2. User authentication layer (SSH-USERAUTH): authenticates the client to the server. Methods: password, publickey, keyboard-interactive (for MFA), hostbased.
  3. Connection layer (SSH-CONNECT): multiplexes multiple channels (sessions, port forwards, X11, SFTP) over one transport.
Client                                              Server
  |--- SSH-TRANS key exchange (Diffie-Hellman) ---|
  |--- Server host key verification (known_hosts) -|
  |--- Encrypted transport established ------------|

  |--- SSH-USERAUTH publickey/password ----------|
  |--- User authenticated -----------------------|

  |--- SSH-CONNECT open channel (session) ------|
  |--- Commands, port forwards, etc. -----------|

Host authentication

The server proves its identity with a host key - a public/private keypair generated when sshd is installed. The public key fingerprint is stored in ~/.ssh/known_hosts on the client after the first connection.

If the fingerprint changes (server reinstall, MITM attempt), the client refuses to connect:

@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!    @
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!

Verify the change is legitimate (server reinstall), update known_hosts, and continue.

User authentication

The client proves its identity. Common methods:

  • password: the user types a password. Sent over the encrypted channel but vulnerable to weak passwords and brute force.
  • publickey: the client proves possession of a private key whose public half is in ~/.ssh/authorized_keys on the server. Recommended.
  • keyboard-interactive: a generic mechanism for challenge-response. Used for one-time passwords, MFA, PAM.
  • hostbased: the client proves it is on a trusted host. Rare; less secure than publickey.

The server’s sshd_config AuthenticationMethods lists the allowed methods and order.

Channels

After authentication, the SSH connection layer opens one or more channels:

  • session: a shell or command.
  • direct-tcpip: client-side port forwarding (local port to remote target).
  • forwarded-tcpip: server-side port forwarding (remote port to client target).
  • x11: X11 forwarding.
  • auth-agent: agent forwarding (ssh-agent).

Multiple channels share one transport - one SSH connection can carry shell sessions, port forwards, and SFTP simultaneously.

SSH versions

VersionStatus
SSH-1Deprecated, insecure. Modern ssh refuses by default.
SSH-2Current standard. All modern systems.

OpenSSH supports SSH-2 only. The server’s sshd_config Protocol directive defaults to 2.

Encryption

SSH-2 negotiates the cipher suite on each connection. Modern preferences:

AlgorithmNotes
chacha20-poly1305@openssh.comDefault on most modern OpenSSH
aes256-gcm@openssh.comAES-GCM, hardware-accelerated
aes128-ctrOlder but still secure

Disable weak algorithms in sshd_config:

Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-ctr

Host key algorithms

Host keys come in several algorithms:

TypeAlgorithm
RSArsa-sha2-512, rsa-sha2-256 (modern signing with RSA keys)
Ed25519Modern, fast, small
ECDSACommon but with concerns about NIST curves
DSADeprecated

Use Ed25519 or RSA (>= 2048 bit). Ed25519 is preferred.

Key exchange

SSH-2 uses Diffie-Hellman key exchange. Modern preferences:

AlgorithmNotes
curve25519-sha256Default in modern OpenSSH
diffie-hellman-group16-sha512Strong, slower

Disable weak groups:

KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group16-sha512

Knowledge check

Knowledge check · 3 questions

  1. Q1. Which SSH layer provides server authentication (host key verification)?

  2. Q2. Multiple SSH channels share one transport connection.

  3. Q3. Which of the following are valid SSH user authentication methods? Select all that apply.

Passing score: 75%. Answers are checked in this browser.