brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ssh -R opens a port on the server that leads back to your machine

Network and access
~/tips/tip-ssh-r-remote-forward

ssh -R 8080:localhost:3000 [email protected]

Make a service on your laptop reachable from a remote server through the SSH connection.

Local forwarding with -L brings a remote port to you. ssh -R does the reverse: it opens a port on the server, and whatever connects there ends up on your side.

Say a dev server runs on port 3000 on your laptop and you want the remote box to reach it:

ssh -R 8080:localhost:3000 [email protected]

On the server, curl http://localhost:8080 now talks to port 3000 on your laptop, through the encrypted connection. Nothing on your side has to be reachable from the internet, which is the nice part when you sit behind a router you do not control.

By default the server binds that port to its loopback address only, so other machines cannot use it. You can ask for another bind address, like -R 0.0.0.0:8080:localhost:3000, but the server only allows that when GatewayPorts in its sshd_config is set to yes or clientspecified. The default is no, and I would leave it that way unless you really mean to publish something.

If you put 0 as the port, the server picks a free one and ssh tells you which.

One warning: anyone who can log in on that server can reach your forwarded service through the loopback port. On a shared machine, only forward things that are safe for every user there.

Further reading: ssh man page, sshd_config man page

More Network and access tips scp -3 alice@server-a:/var/backups/db.sql.gz bob@server-b:/srv/restore/ tailscale exit-node suggest tailscale lock sign nodekey:1abddef1 tlpub:abcdef12 wg genpsk > peer1.psk Table = off All Network and access tips (163) All topics

Link