Skip to content

Instantly share code, notes, and snippets.

@FMCorz
Last active September 27, 2025 02:39
Show Gist options
  • Save FMCorz/6f84985f96c5c7f9f4c9a73f31f79d21 to your computer and use it in GitHub Desktop.
Save FMCorz/6f84985f96c5c7f9f4c9a73f31f79d21 to your computer and use it in GitHub Desktop.
Port forwarding using SSH

Local port forwarding

ssh -nNT -L LOCALPORT:DESTINATION:DESTPORT SSHACCOUNT

To forward localhost:5000 to destination.net:80:

ssh -nNT -L 5000:destination.net:80 [email protected]

Proxy HTTP

ssh -nNT -D LOCALPORT SSHACCOUNT

Using the following, the local port 8080 will proxied through example.net.

ssh -nNT -D 8080 [email protected]

Then, set-up your browser:

SOCKS host: localhost
      port: 8080
      
  [x] Socks v5

Arguments explained

  • -n Redirects stdin from /dev/null (actually, prevents reading from stdin). This must be used when ssh is run in the background.
  • -N Do not execute a remote command. This is useful for just forwarding ports (protocol version 2 only).
  • -T Disable pseudo-terminal allocation.
  • -L [bind_address:]port:host:hostport Local port forward to host:hostport
  • -D [bind_address:]port Local dynamic application-level port forwarding
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment