Linux – How to configure ssh tunneling with Putty between two RHEL servers

linuxputtyrhel6sshssh-tunnel

I'm trying to allow ssh access from a remote RHEL server to a local RHEL box via Win/Putty gateway. Basically, I'd like to be able to do 'ssh localhost -p 512' on a remote server so that it would connect to the RHEL server in the local network. The local network is beyond a firewall so I can connect from my Win PC to the remote server with Putty/ssh but not vice verse.

LclSrv—-WinXP/Putty—–||—–RmtSrv

So, I've added the following tunneling settings to the current RmtSrv session in Putty (actually I use Kitty but doesn't matter):

R512 LclSrv:22

I expect that this would create a process on the remote server that listens port 512 and transfers the connections to a local network/LclSrv port 22.

After pressing start button, Putty opens a regular ssh terminal session successfully but nothing happens. (options show active port forwarding). I've checked with netstat -l that port 512 is not listening on RmtSrv. ssh on this port returns 'connection refused'. What am I doing wrong? May be there is something in the sshd_config that needs to be changed in order to allow the tunneling? Could it be user privileges on RmtSrv that prevents me from creating tunnels? I have sudo btw.

Cheers, Vlad.

Best Answer

Local port forwarding scenario (rmtsrv has access to WinXP):

What you want to do in ssh terms is forward a local port to another machine and allow other hosts (rmtsrv) to connect to it.

So you set up local WinXP:512 to forward to lclsrv:22.

So in Putty's Tunnel settings be sure to check Local ports accept connections from other hosts and add source port 512 with the destination lclsrv:22 to the forwarded ports.

Edit to accommodate comment: Remote port forwarding scenario (WinXP has access to both srvs):

The configuration you suggest should work.

r512 LclSrv:22

Is correct. I'd guess the issue is with the sshd security settings on rmtsrv. Check if this is enabled:

AllowTcpForwarding yes

If you want to enable access to the forwarded port for others on rmtsrvs network:

GatewayPorts yes

The config usually resides in '/etc/ssh/sshd_config