SSH tunnel config .ssh/config
SSH tunnels can be pre-configured in the client-side SSH configuration file (~/.ssh/config
),
allowing automated and seamless port forwarding without manually entering commands.
-L
)
Local port forwarding allows a local port to securely connect to a remote service.
Host remote-mysql
HostName remote-server
User user
LocalForward 8080 localhost:3306
LocalForward 8080 localhost:3306
→ Maps local port 8080 to remote MySQL port 3306.remote-mysql
, the tunnel is automatically established.-R
)
Remote port forwarding allows a remote machine to connect back to a local service.
Host remote-ssh-access
HostName remote-server
User user
RemoteForward 9090 localhost:22
RemoteForward 9090 localhost:22
→ Maps remote port 9090 to local SSH port 22.-D
)Dynamic port forwarding creates a SOCKS5 proxy, allowing multiple applications to route traffic securely through the SSH connection.
Host socks-proxy
HostName remote-server
User user
DynamicForward 1080
DynamicForward 1080
→ Sets up a SOCKS5 proxy at localhost:1080
.
ServerAliveInterval 60
ServerAliveCountMax 2
ExitOnForwardFailure no
HostName remote-server.example.com
User user
IdentityFile ~/.ssh/id_rsa
ssh remote-mysql
instead of typing the full hostname.LocalForward
→ Securely connect to a remote service.RemoteForward
→ Allow a remote machine to access a local service.DynamicForward
→ Set up a SOCKS5 proxy for secure browsing.ServerAliveInterval
→ Prevent SSH timeouts.ExitOnForwardFailure
→ Ensure automatic reconnection.🚀 Now, SSH tunnels are automatically created when connecting to the configured hosts! 🔐