SSH tunnels and port forwarding on a Mac without the command line
Short answer. SSH port forwarding comes in three kinds: -L brings a remote port to your Mac, -R offers a port of your Mac to the server's side, and -D turns the connection into a SOCKS proxy. You can save any of them in ~/.ssh/config, or use an app that keeps a list of tunnels with Start and Stop buttons. All three listen on the loopback address unless you say otherwise. Keep it that way.
An SSH tunnel on a Mac is one line in Terminal, until you need five of them, need to remember which is running, and need to find the stray ssh process that still holds port 8080. This article explains the three kinds of forwarding with plain examples, how to save them, the mistakes that expose more than you meant to, and how MyXterm's Tunnels tab handles them without a command line.
Local forwarding (-L): a remote port on your Mac
You can reach a bastion over SSH, and behind it sits a web console you can't reach directly. A local forward makes that console appear on your own machine [1]:
ssh -N -L 8080:192.0.2.20:80 [email protected]
Now http://127.0.0.1:8080 in your browser shows the page from 192.0.2.20. -N tells ssh not to run a remote command, which is what you want when the connection only carries forwards.
The address after the first port is resolved on the far side. -L 5432:localhost:5432 means the SSH server's own port 5432
, not your Mac's.
Remote forwarding (-R): a port of your Mac on the server
The other direction: something on the server's side needs to reach a service on your Mac, for example a development web server on port 3000 [1]:
ssh -N -R 9000:127.0.0.1:3000 [email protected]
Port 9000 on the bastion now leads to port 3000 on your Mac. By default the server binds that port to its loopback interface only, so only programs on the bastion itself can use it.
Dynamic forwarding (-D): a SOCKS proxy
When you need many targets behind the same server, don't add a forward for each. A dynamic forward makes ssh act as a SOCKS server, and it supports SOCKS4 and SOCKS5 [1]:
ssh -N -D 1080 [email protected]
Point a browser's SOCKS proxy setting at 127.0.0.1, port 1080, and every page it loads goes out through the bastion. Use a separate browser profile for this, so the rest of your browsing doesn't go the same way.
Save it in ~/.ssh/config
Each option has a keyword in ~/.ssh/config [2], so a tunnel can have a name:
Host intranet-web
HostName bastion.example.com
User admin
LocalForward 8080 192.0.2.20:80
ExitOnForwardFailure yes
ServerAliveInterval 30
# RemoteForward 9000 127.0.0.1:3000
# DynamicForward 1080
ssh -N intranet-web starts it and Ctrl-C stops it. With -f it goes to the background, and from then on you manage it as a process: find it, check that it is still alive, kill it. That bookkeeping is the gap a tunnel manager fills.
Common pitfalls
- The bind address. A forward may start with an address to listen on:
-L 0.0.0.0:8080:192.0.2.20:80, or the-goption, lets other machines connect to the port [1]. On an office or café network that hands your intranet page to everyone nearby. Leave the address out, or write127.0.0.1. - GatewayPorts. For remote forwards the decision is the server's. A bind address in
-Ronly works if the server'sGatewayPortsoption allows it, and the default is no [3]. Think twice before asking for it to be switched on for everyone. - Address already in use. Something else holds the local port, often an older
ssh. WithoutExitOnForwardFailure yes,sshstays connected with no forward and you stare at a browser error. - Ports below 1024. Only the superuser can forward privileged ports [1]. Listen on 8443 instead of 443.
- The server says no.
AllowTcpForwardingandPermitOpenin the server's configuration can forbid forwarding or limit its targets [3]. - The last hop is not encrypted. SSH protects the path to the server. From the server to the target the traffic is whatever the application sends.
- Sleep. A laptop that sleeps kills the connection.
ServerAliveIntervalmakessshnotice, but it doesn't reconnect by itself.
Tunnels without the command line: MyXterm
MyXterm is a free, open-source (Apache-2.0) connection manager and terminal for macOS, Linux and Windows. v0.1.0 is the first stable release. macOS builds are signed and notarized; Windows and Linux builds are not code-signed yet.
Its Tunnels tab (the Tunnels button in the command bar, or the command palette) is a list of saved forwards partial TUN-001 [4]:
- One form for all three kinds. Name, type (
Local → remote
,Remote → local
orSOCKS proxy
), listen port and target. - The SSH server is chosen, never assumed. You search your saved SSH sessions, with their environment shown, or type
user@host. Nothing is preselected, so a tunnel never rides a production host by accident. - Start and Stop, with a state. Each row shows Stopped, Starting, Up, or Failed with the reason. A dropped tunnel reconnects with a growing delay of at most 60 seconds. Tunnels keep running when you close the tab and stop when MyXterm quits.
- Loopback by default. The form has no bind address: a tunnel made in the app listens on
127.0.0.1. The engine refuses any other address unless the tunnel's entry explicitly allows it. - Conflicts found early. Two tunnels on the same port get a warning in the list, and a busy port is detected before the start with a message that names it, such as
port 8080 on 127.0.0.1 is already in use
. - Open. A running local forward to a common web port gets an Open button for your browser.
- Start with the app. A tunnel can start when MyXterm opens; that is never done for a tunnel through a PROD session.
Under the form MyXterm runs the system's OpenSSH client with -N, ExitOnForwardFailure and a 30-second keepalive, passing each value as a separate argument and never through a shell. When you stop a tunnel it stops that ssh and everything it started, and after a crash MyXterm closes what was left behind the next time it runs.
What MyXterm's tunnels don't do yet
- Keys or an agent only. A tunnel can't ask for a password, a key passphrase or a one-time code, and the server's host key must already be trusted. Connect to the server once in a terminal tab first.
- What was tested. Automated tests use a stand-in for
sshand the realsshagainst a closed loopback port. By hand, a local forward was checked against a lab VM: the service answered through the tunnel, and nosshprocess was left after Stop. - Not verified: Windows (the code compiles there but hasn't been verified), IPv6, tunnels through jump hosts, behaviour after sleep and wake, and long runs of repeated starts and stops.
- Not in the form yet: tunnel groups and listening on a network address. A topology view is planned TUN-002.
- PuTTY forwards aren't imported. The PuTTY importer reports a session's port forwardings but doesn't create tunnels from them; see moving PuTTY sessions.
Download MyXterm for Mac Features and status
FAQ
Is there a GUI for SSH tunnels on a Mac?
macOS itself has none: the built-in way is the ssh command or ~/.ssh/config. MyXterm, which is free and open source, has a Tunnels tab that saves local, remote and SOCKS forwards and starts and stops them with a button. It is a young project, and its tunnels sign in with keys or an agent only.
What is the difference between ssh -L, -R and -D?
-L listens on your computer and sends connections to a target that the SSH server can reach. -R listens on the SSH server and sends connections back to a target that your computer can reach. -D listens on your computer as a SOCKS proxy, so each program picks its own target.
Why can't other computers reach my forwarded port?
A forwarded port listens on the loopback address by default, so only programs on the same machine can use it. That is the safe default. Listening on a network address needs an explicit bind address or the GatewayPorts option, and it exposes whatever is behind the tunnel to that network.
How do I keep an SSH tunnel from dropping?
Set ServerAliveInterval so that ssh notices a dead connection, and ExitOnForwardFailure so that it exits instead of running without the forward. ssh does not reconnect by itself: a tunnel manager or a small script has to start it again.
Sources
All read on 4 December 2026. Addresses in the examples are documentation addresses (RFC 5737) and example.com. MyXterm statuses are from features.toml on the same day; partial
means it works in the app but does not meet its full acceptance criteria yet.
- OpenSSH,
sshmanual page (-L,-R,-D,-N,-g): man.openbsd.org/ssh - OpenSSH,
ssh_configmanual page (LocalForward,RemoteForward,DynamicForward,ExitOnForwardFailure): man.openbsd.org/ssh_config - OpenSSH,
sshd_configmanual page (GatewayPorts,AllowTcpForwarding,PermitOpen): man.openbsd.org/sshd_config - MyXterm tunnels: crates/tunnels/src/lib.rs, apps/desktop/src/tunnels_view.rs, the Tunnels entries in CHANGELOG.md, and TUN-001 in features.toml
Last updated