What Changes When stunnel Wraps SSH in TLS? Linux and Windows Examples
SSH is still SSH when it listens on port 443. In the article on accepting SSH on port 443, OpenSSH accepts the connection directly and starts speaking SSH. Put stunnel in front of it and two things change: which process accepts the external connection, and which protocol runs on that leg.
The example uses ssh.example.com:8443 as the external TLS endpoint on a pre-approved test path. The focus is on which process handles each connection on Linux and Windows, and where to look when authentication fails.
Ports and protocols are separate
Section titled “Ports and protocols are separate”A port helps select the socket that accepts a connection. The program that accepts it determines what protocol comes next. In a direct connection, OpenSSH starts speaking SSH on the incoming socket. With stunnel, the server-side stunnel terminates TLS and relays SSH bytes to OpenSSH behind it.[1][2]
Illustration by noisonnoiton. Blue marks legs that carry SSH; green marks the outer TLS leg.
| Question | Direct OpenSSH | OpenSSH behind stunnel |
|---|---|---|
| Which process accepts the external connection? | OpenSSH | Server-side stunnel |
| What is exchanged first on that connection? | SSH version strings | TLS handshake messages |
| Which connection does OpenSSH see? | The TCP connection opened by the SSH client | A separate TCP connection opened by server-side stunnel |
The data inside TLS is still SSH. stunnel does not construct or handle HTTP requests. Calling this path HTTPS or an HTTP proxy just because it uses TLS misidentifies the protocol being carried.[1][2]
TLS and SSH authenticate different things
Section titled “TLS and SSH authenticate different things”The SSH client connects to the client-side stunnel listener on its own host’s loopback interface. That stunnel opens a TLS session to its server-side peer at ssh.example.com:8443. The server-side stunnel passes the SSH bytes to OpenSSH on the server’s loopback interface. The SSH client and OpenSSH, not the stunnel processes, are the endpoints of SSH key exchange and user authentication.[1][2]

Diagram by noisonnoiton. This PlantUML diagram shows the logical flow, not a packet capture.
- TLS server authentication: The client-side stunnel uses
verifyChainand the configured trust anchors to validate the certificate chain.checkHostseparately verifies that the certificate covers the expected name,ssh.example.com. The private key for the TLS certificate stays on the server that runs server-side stunnel.[1][3] - SSH host authentication: OpenSSH proves its server identity with its SSH host key. The SSH client checks that key against the key it expects in
known_hosts. When connecting to a local listener, it can useHostKeyAliasto look up the key forssh.example.com. The SSH host private key also stays on the server.[8][9] - SSH user authentication: OpenSSH checks that the user holds the private key corresponding to a public key authorized for the account. The user’s private key stays on the client side. A valid TLS server certificate does not grant access to an SSH account.[5][6][9]
Where the roles sit on Linux and Windows
Section titled “Where the roles sit on Linux and Windows”Both examples put a TLS listener at ssh.example.com:8443 and an SSH listener on the server’s loopback interface. What changes across platforms is how the services are managed and where the OpenSSH configuration lives, not the protocols.[2][5][6]
| Item | Linux (Ubuntu example) | Windows |
|---|---|---|
| External TLS listener | stunnel runs in server mode. accept is the external listener; connect points to OpenSSH on loopback. cert and key supply the TLS credentials.[1][2] | The same server-mode settings apply. stunnel runs as a separate Windows service from OpenSSH.[1][2][4] |
| Internal SSH listener | When sshd listens directly, ListenAddress and Port in sshd_config specify the binding.[9] If a systemd socket owns the listener instead, inspect the socket for the effective binding.[10] | OpenSSH Server reads %ProgramData%\ssh\sshd_config by default. sshd accepts the internal SSH connection.[5][7][9] |
| Service management | Ubuntu documents the OpenSSH unit as ssh.service. This example uses a package-provided systemd unit for stunnel.[2][6] | Microsoft documents sshd as the OpenSSH Server service name. The stunnel manual distinguishes -install and -start for its separate Windows service.[1][7] |
The client-side settings follow the same design in both examples. In client mode, accept stays on loopback and connect points to the external TLS endpoint. The SSH client dials the local listener’s port, not the server’s external port 8443.[1][2]
Find where the connection failed
Section titled “Find where the connection failed”| Last observed stage | Where to look |
|---|---|
| External TCP does not connect | Check the approved path and confirm that server-side stunnel is listening on 8443. Without a TCP connection, the TLS handshake cannot start. |
| TCP connects, but the TLS certificate is rejected | Check the client-side stunnel log. A CA chain error is different from a name mismatch for ssh.example.com. Fix the cause rather than disabling verification.[3] |
| TLS succeeds, but the SSH host key is rejected | Check which name the SSH client looked up in known_hosts. Do not accept an unexpected key before verifying it through a trusted channel.[8] |
| The host key checks out, but public-key authentication is rejected | Check which user key the SSH client offered and which public keys OpenSSH authorizes for the target account.[5][6][8] |
If TLS succeeds but there is no SSH version exchange, first check whether server-side stunnel reached the internal OpenSSH listener. TLS success does not establish that the back-end SSH listener is healthy.[1][2]
An independent stunnel listener cannot simply bind to the same IP address and TCP port already occupied by an HTTPS listener. Running both roles requires separate bindings or an approved listener design. Get approval for the path, listener, and intended use before operating it.
What was tested and what was not
Section titled “What was tested and what was not”A Linux loopback test with stunnel 5.72 and OpenSSH 9.6p1 confirmed SSH public-key authentication and command execution after TLS verification. The test rejected an untrusted CA, a mismatched TLS hostname, an unexpected SSH host key, and an unauthorized user key in separate cases. It did not exercise installed systemd services or an external network path.
The Windows example maps the server roles from official stunnel and Microsoft documentation. Windows service startup and connections were not tested. The official documentation was checked on 2026-11-30.
Sources
Section titled “Sources”[1] stunnel Manual
[2] stunnel HOWTO
[4] stunnel Windows Configuration
[5] Microsoft: OpenSSH Server configuration
[6] Ubuntu Server: OpenSSH server