Disabling SSH TCP forwarding prevents users from tunneling arbitrary TCP traffic through SSH sessions, closing off an easy way to bypass firewalls, egress controls, and network monitoring. Restricting forwarding is especially useful on bastion hosts, jump servers, and multi-user systems where shell access is allowed but network paths must remain tightly controlled.
In OpenSSH, TCP forwarding behavior is controlled on the server by directives in /etc/ssh/sshd_config such as AllowTcpForwarding and PermitOpen. These directives determine whether local and remote port forwarding are permitted at all, and optionally which destination host and port pairs can be reached through those tunnels. Settings can be applied globally or refined in Match blocks for specific users, groups, or source addresses.
Changing forwarding policy affects every SSH session handled by sshd and can break workflows that rely on tunnels, including database access, SOCKS proxies, or custom port mappings. Configuration changes should therefore be staged with a fallback access path, validated with sshd -t before restarting the service, and verified from a separate client to confirm that forwarding is truly blocked without locking out required access.
Related: How to forward local port in SSH
Related: How to forward a remote port in SSH
Related: How to apply conditional SSH settings
$ whoami
user
$ sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup $ ls -l /etc/ssh/sshd_config* -rw-r--r-- 1 root root 3554 Jan 10 12:26 /etc/ssh/sshd_config -rw-r--r-- 1 root root 3554 Jan 10 20:31 /etc/ssh/sshd_config.backup /etc/ssh/sshd_config.d: total 0
The backup copy allows quick restoration if a configuration error prevents sshd from starting.
$ sudo nano /etc/ssh/sshd_config
Incorrect syntax in /etc/ssh/sshd_config can stop sshd from starting and block new SSH logins until the file is fixed.
/etc/ssh/sshd_config AllowTcpForwarding no
AllowTcpForwarding no disables both local and remote TCP forwarding for sessions that use the global configuration unless a later Match block overrides it.
/etc/ssh/sshd_config PermitOpen none
PermitOpen limits which host:port pairs may be used for forwarding; setting it to none blocks all TCP forwarding destinations for sessions that use this stanza.
/etc/ssh/sshd_config
AllowTcpForwarding no
PermitOpen none
Match User tunneluser
AllowTcpForwarding yes
PermitOpen localhost:5432
Ensuring forwarding is enabled only where strictly required reduces the attack surface of bastion hosts and shared administrative accounts.
$ sudo sshd -t
No output from sshd -t indicates that the configuration is syntactically valid.
Related: How to test SSH server configuration
$ sudo systemctl restart ssh
On some distributions the service name is sshd instead of ssh, for example sudo systemctl restart sshd.
$ sudo systemctl status ssh ● ssh.service - OpenBSD Secure Shell server Loaded: loaded (/usr/lib/systemd/system/ssh.service; enabled; preset: enabled) Active: active (running) since Sat 2026-01-10 20:31:40 +08; 136ms ago TriggeredBy: ● ssh.socket Docs: man:sshd(8) man:sshd_config(5) Process: 14689 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS) Main PID: 14692 (sshd) Tasks: 1 (limit: 4546) Memory: 2.6M (peak: 3.6M) CPU: 31ms CGroup: /system.slice/ssh.service └─14692 \"sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups\" ##### snipped #####
$ ssh -v -L 10080:example.com:80 user@host.example.net ##### snipped ##### channel 2: open failed: administratively prohibited: open failed
The administratively prohibited error confirms that SSH TCP forwarding is disabled by the server configuration.