How do I set up a port forwarding through SSH?

I have a shell account (Debian) and I want all my localhost browser internet traffic to go through that shell account.

I know how to configure the internet browser and how to configure Putty for port forwarding, what I do not know is what I need to do on the server for this to happen.

Anyone knows what I should do on the server so that it will accept port forwarding? It does not seem to work with the default configuration.


Solution 1:

Inside the sshd_config file just change the #PermitTunnel setting from no to yes.

from

#PermitTunnel no

to

PermitTunnel yes

Solution 2:

I want all my localhost browser internet traffic to go through that shell account.

ssh -D 8080 -T -f -l username proxy_host
  • Will create a dynamic port forwarding (SOCKS proxy).
  • -T will not allocate a tty
  • -f will make SSH to go immediately into background
    • For this to work you need to use public key authentication
    • at least on debian have a look at ssh-copy-id
  • Now you just need to configure your browser to go thru the specified port

Leave out -Tand -f while testing the setup. The local port forwarding (-L [listenaddress]:localport:remotehost:remoteport ssh_host) will only work for the remotehost (e.g. ssh -L 8080:google.com:80 ssh_host will only forward traffic to google.com over the ssh_host not all web traffic)

If that doesn't work please update your question with the output of the SSH command with the -vvv switch added.

Solution 3:

When using ssh -R 8080:google.com:80 ssh_host

on sshd_config

GatewayPorts yes

should be to listen on wildcard or external interface not just loopback.