Course contentsShow
← Security
Lesson 504 of 3,05211. Network Security - VPNs and TunnelingFree lesson

SSH Configuration for Tunneling

Configuring sshd_config and ssh_config for tunnel control, AllowTcpForwarding, and PermitTunnel options.

SSH Configuration for Tunneling

What you'll learn: How to configure SSH server and client settings to control whether tunneling is allowed, restricted, or prohibited.


SSH tunneling is powerful, but with great power comes the need for proper access control. Both the SSH server (sshd) and client configurations determine whether tunneling features are available. As an administrator, you control this through specific directives in configuration files.


Server Configuration: /etc/ssh/sshd_config

The SSH server configuration file controls what tunneling features users can employ when connecting to your server:

AllowTcpForwarding controls port forwarding (both local and remote):

  • yes — permits all port forwarding (default on many systems)
  • no — blocks all port forwarding completely
  • local — allows local forwarding (-L) but blocks remote (-R)
  • remote — allows remote forwarding (-R) but blocks local (-L)

PermitTunnel controls TUN/TAP device tunneling (layer 3 VPN-like functionality):

  • yes — allows layer 3 network tunneling
  • no — blocks device tunneling (default)
  • point-to-point — allows only P2P tunnels
  • ethernet — allows only ethernet-layer tunnels

GatewayPorts controls whether remote forwarding binds to all interfaces or just localhost (useful with -R).

Think of these as security checkpoints: AllowTcpForwarding guards the door to port forwarding, while PermitTunnel guards the deeper VPN-like capabilities.


Client Configuration: ~/.ssh/config

Client-side settings in ~/.ssh/config can pre-configure tunneling behavior per host, though the server always has final say. You can specify default forwarding rules, dynamic port settings, and more using LocalForward, RemoteForward, and DynamicForward directives.


Key Takeaway:
Control SSH tunneling security by configuring AllowTcpForwarding and PermitTunnel in sshd_config on the server—these directives determine whether users can create tunnels, acting as essential access control mechanisms.