← Blog

Date:Mon, 16 Nov 2026 From:Thomas Gumz <thomas@lograker.app> To:You Subject:

SSH through SSH, in pure Swift

A potential customer wrote to me the other day asking whether LogRaker could follow logs on their EC2 instances behind an AWS target group. The honest answer was “not yet”, and the first thing standing in the way wasn’t AWS at all, it was plain old networking. Instances like that often only have private addresses, so you need a way in. A VPN is one (and if you have one, LogRaker already works through it like any other app on your Mac), and AWS has two of its own, Systems Manager Session Manager and EC2 Instance Connect Endpoint, which LogRaker doesn’t support at the moment. But plenty of setups simply use a single machine that faces the internet, the bastion, or jump host. On the command line that’s a one-liner, ssh -J bastion 10.0.1.5, and you never think about it again.

LogRaker can’t do that one-liner, though. It doesn’t run ssh at all, it talks SSH itself through swift-nio-ssh (I wrote about why, and the RSA fork that came out of it), so whatever -J does, I had to do myself.

What ssh -J actually does

It’s less magic than it sounds. Your Mac opens a normal SSH connection to the jump host, then asks it to open a TCP connection to 10.0.1.5:22 on its behalf. SSH has a channel type just for that, direct-tcpip (RFC 4254, section 7.2), and the jump host then shovels bytes back and forth between that channel and the target. Inside that channel your Mac runs a second, completely separate SSH session with the target, with its own handshake, its own host key and its own login, end to end encrypted, so the jump host only ever sees ciphertext going by.

So in swift-nio-ssh terms that’s one NIOSSHHandler riding inside a child channel of another NIOSSHHandler. Before writing any app code I built a tiny throwaway program against the Cerbo GX on my boat to see if that even works, and it did:

jumpHandler.createChannel(promise, channelType: .directTCPIP(target)) { child, _ in
    child.eventLoop.makeCompletedFuture {
        try child.pipeline.syncOperations.addHandlers([
            TunnelWrapperHandler(),   // SSHChannelData <-> ByteBuffer
            NIOSSHHandler(role: .client(targetConfig), allocator: child.allocator,
                          inboundChildChannelInitializer: nil),
            ErrorHandler(),
        ])
    }
}

The one piece you have to bring yourself is that wrapper. A child channel hands you SSHChannelData, but an NIOSSHHandler wants raw bytes, the same as it would get from a TCP socket, so the wrapper just unwraps on the way in and wraps on the way out (nio-ssh’s own NIOSSHClient example has the same thing for its port forwarding). The handshake with the target starts by itself the moment the child channel goes active, and from then on that child channel is the connection, so everything LogRaker builds on top of a session (Streams, the Terminal, the clock probe, and so on) works through it without knowing the difference.

A few other things the spike told me: the target’s name gets looked up by the jump host, not by my Mac, so private names like ip-10-0-1-5.ec2.internal just work. Several channels on both hops at once, over a single jump connection, were no problem either. And if the jump connection drops, a command running on the target fails right away instead of hanging, which is exactly what you want.

A jump host is just another Source

In the app I kept it as simple as I could. A jump host is an ordinary SSH Source with its own host, user, key and trust, and every other SSH Source gets a ‘Jump Host’ menu that lists the SSH Sources in the same Workspace. If yours isn’t there yet, ‘New Jump Host…’ opens a second editor right on top of the first one. A jump host can have a jump host of its own (I cap the chain at four, which is plenty), and all the Sources behind one jump host share its single connection, the same one its own Streams already use.

If you already have a ProxyJump line in ~/.ssh/config, picking that alias in the Host menu picks the matching Source as its jump host, or offers to create it pre-filled from that entry if it doesn’t exist yet (that part is in the Web edition only, since the App Store one can’t read that file).

The one change to the fork

Of course, there was one catch. When a jump host refuses to open the tunnel, the server sends back a reason code, and the two that matter are 1 (“administratively prohibited”, meaning someone set AllowTcpForwarding no on the jump host) and 2 (“connect failed”, meaning the jump host tried but couldn’t reach the target). Those call for completely different fixes, one is a config change on the bastion and the other is a typo in your host name, so the error message should say which.

swift-nio-ssh does receive that code, but it only keeps it inside the text of the error ("Reason: 2 open failed"), and I really didn’t want to parse error strings to tell them apart. So the fork now also carries it as a plain number, NIOSSHError.channelOpenFailureReasonCode. It’s a tiny change, one source file and one test, marked LOGRAKER FORK: like everything else in there, and published as 0.15.0-rsa.3.

Where it went sideways (in testing, luckily)

The tunnel itself was the easy part. The bugs were all in the things around it, and all three of them showed up while I was testing it myself, so here they are.

The prompt that trusted the wrong machine. I don’t have a real bastion on the boat, so for testing I set up a Source with Host 127.0.0.1 and the Cerbo GX as its jump host. Since the jump host looks up the address, 127.0.0.1 means the Cerbo GX itself, so it’s the Cerbo tunneling right back into itself, which is silly but a perfectly good test. Then I deleted that Source to try again, made a new one… and forgot to pick the jump host. LogRaker happily connected to 127.0.0.1 on my Mac instead (Remote Login is on), showed me a trust prompt for “127.0.0.1”, and I clicked Trust.

Of course, that prompt looked exactly like the one for the Cerbo, because trust was stored by host name and port, and 127.0.0.1:22 is 127.0.0.1:22 no matter who you ask. OpenSSH has the same blind spot by the way, which is what its HostKeyAlias option is for. But behind a jump host the same address really is a different machine, and the same goes for two VPCs that both use 10.0.1.5, so now a server behind a jump host is trusted together with that jump host, and the prompt says so: “Trust server 127.0.0.1 via cerbo.lan?”. Settings shows it the same way.

The timeout that didn’t wait for me. The first time it all worked, it still failed. I got the trust prompt for the target, took a few seconds to read it, clicked Trust, and got “Timed out after 12s”. The log showed the session coming up just fine, 16 seconds after it started, because Auto-Detect’s timer had kept ticking the whole time the prompt sat there waiting for me. That bug was there for direct connections too, it was just easier to hit with a second prompt in the mix. Now the timer stops while a trust prompt is on screen and starts fresh once you answer it (and it’s 10 seconds now instead of the odd 12).

The clock that was ten seconds off. LogRaker measures each server’s clock offset so it can line up logs from different machines, and right after the trust prompt fix the new Source told me its clock was 6.62 seconds off. Then 10.17 seconds. The Cerbo GX’s clock is fine… it turned out Auto-Detect took one single sample and started its stopwatch before connecting, so however long I spent reading the trust prompt landed right in the round trip, and half of that showed up as clock offset. Duh! Now it does what Test Connection always did, five samples, each one timed after the login, and keeps the quickest. Same test, same wait at the prompt: -0.585 seconds.

So…

Jump hosts are in LogRaker 3.1, for Streams, the Terminal and everything else that talks SSH, and the docs have the details.

If you have servers you can only reach through a bastion, give LogRaker a try, and let me know how it goes!

Thanks for reading!