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: Tag and ssh -P give one SSH host several profiles

Network and access
~/tips/tip-ssh-tag-p-profiles

Match tagged tunnel

Switch a block of ssh_config settings on per command with a tag name.

Sometimes you want the same server with different settings: a plain shell most of the time, and a connection with port forwards when you are working on something. A tag selects that from the command line.

In ssh_config you write a Match tagged block. It only applies when that tag is set:

Match tagged tunnel
    LocalForward 8080 127.0.0.1:80
    LocalForward 5432 127.0.0.1:5432
    ExitOnForwardFailure yes

Then -P sets the tag for one run:

ssh -P tunnel server

Without -P tunnel, ssh server behaves as usual. With it, you get the forwards too. You can also put Tag tunnel inside a Host block to set a default tag for that host.

I find this cleaner than inventing fake host names like server-tunnel, because the host key, user and address stay in one place and only the extra behaviour lives in the tagged block.

The Tag keyword and Match tagged arrived in OpenSSH 9.4, so check ssh -V on every machine that shares the config. An older ssh stops with an error about an unsupported option rather than ignoring it.

Further reading: ssh_config man page, ssh 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