SSH tunnel to MS SQL Server works with PuTTY but not from ssh command line

puttysql serversshssh-tunnel

I'm trying to create an SSH tunnel to MS SQL Server from my Windows 10 local computer. When I create a tunnel with PuTTY, it works flawlessly. But when I create the same tunnel in command line (OpenSSH_for_Windows_9.1p1, LibreSSL 3.6.1) like this

ssh -i ecdsa_id -L 1433:192.168.1.22:1433 user@remote

the tunnel is created, but the connection to the DB is not possible (error "[Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: No connection could be made because the target machine actively refused it."). On the server, in sshd log there is absolutely no communication. If I create the same command line tunnel for MySQL (or any other service running on the server) it works as expected, connection attempts appear in the sshd log.

I've tried a lot of different settings, different ports, any advice I could find, but nothing helps.

Does anyone know what PuTTY does differently, that its tunnel works and command line ssh does not, or what should I try to get it working? Thank you.

Best Answer

OMG, after three days of trying virtually every possible setting I have just found out, what the problem was. My PDO connection string looked like this

sqlsrv:Server=localhost,1433;Database=test

and it worked with PuTTY created tunnel but NOT with ssh command line. Now it occurred to me, that I can try

sqlsrv:Server=127.0.0.1,1433;Database=test

and everything works as expected.

Strangely enough, PDO driver for MySql works with "localhost"

mysql:host=localhost;port=3336;dbname=test

regardless of what method I use to create a tunnel.

I tried to ping localhost and it resolves to "::1" (IPv6) which I guess is the reason why it didn't work. PuTTY probably has this covered.

Related Question