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: DisableForwarding yes switches off every kind of SSH tunnel in one line

Network and access
~/tips/tip-sshd-disableforwarding

DisableForwarding yes

Stop users from using your SSH server as a tunnel or proxy into your network.

An SSH login is more than a shell. With -L, -R and -D a user can turn your server into a tunnel into the network behind it. On a bastion or a file drop, I do not want that.

One line in sshd_config covers it:

DisableForwarding yes

The man page says it disables all forwarding: X11, the ssh agent, TCP and Unix sockets, and it overrides the separate options like AllowTcpForwarding and AllowAgentForwarding. That is easier than setting four options and hoping you did not miss one.

It works inside a Match block too, so you can keep forwarding for yourself and block it for the rest:

Match User *,!alice
    DisableForwarding yes

Then sudo sshd -t and a restart. A quick test from a client: ssh -N -L 8080:127.0.0.1:80 [email protected] should now print a refusal as soon as you use the forward.

The man page is honest about the limit. If a user has a normal shell, they can install their own forwarder, so blocking tunnels only really holds together with a restricted account, like an SFTP-only user or a forced command. And if you jump through this host with ProxyJump, that also counts as forwarding and stops working.

Further reading: 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