Open SSH tunnel and connect to MySQL

1

2

Hi I'm trying to use PuTTY to open a SSH tunnel and connect to a remote MySQL server.

PuTTY:

  1. Remote SSH Server IP and port

  2. MySQL Port on the remote server

  3. Tunnel: Local address and port on local machine (I have MySQL Server installed locally, so I'm using 3307 and not 3306 on local machine so there is no conflict with local MySQL Server)

enter image description here enter image description here

Si I click open, PuTTY asks for an username and password which I provide, if the logon is successful PuTTY immediately closes itself with out any messages or errors

putty.log shows this:

=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2017.08.23 07:29:08 =~=~=~=~=~=~=~=~=~=~=~=

login as: myUser
Using keyboard-interactive authentication.
Password for myUser@Server:
Could not chdir to home directory /home/myUser: No such file or directory
This service allows sftp connections only.

Now, If I try to connect with MySQL Workbench using the option Standard TCP/IP over SSH, it works...

enter image description here

I've read in forums that the solution is to tweak the options on the SSH server, but I don't have any control over the SSH Server.

Although I can use WorkBench to connect to the database, the goal here, is to have Putty open the SSH tunnel.

How can I open the SSH tunnel with PuTTY? What am I doing wrong? How can I solve this without altering the server?


Using plink: getting the same result

enter image description here


EDIT

I disabled the Don't start a shell or command at all option as Martin suggested, now I don't receive the SFTP error, but after typing the password nothing happens

The log is just writing what I see in the screen:

=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2017.08.23 10:07:25 =~=~=~=~=~=~=~=~=~=~=~=
login as: user
Using keyboard-interactive authentication.
Password for user@server:

EDIT 2 - SOLVED

After following Martin Prikryl advice:

I swapped the ports: L3307 -> 127.0.0.1:3306

enter image description here

Putty event Log now says: Access granted - Local port 3307 forwarding to 127.0.0.1:3306

Now MySQL WorkBench is able to connect to 127.0.0.1:3307 successfully

Thanks!

In case you need to do this with PLINK, here is how I did it:

plink.exe SSH_SERVER_IP_OR_ADDRESS -P 2204 -ssh -l USER -pw PASSWORD -L 3307:127.0.0.1:3306 -N -v

The One

Posted 2017-08-23T14:28:34.810

Reputation: 113

You have 2 and 3 labeled other way around. – Martin Prikryl – 2017-08-23T14:35:44.243

Answers

1

Try checking:
Connection > SSH > Protocol options > Don't start a shell or command at all.


You also have a local and remote port of the tunnel swapped.

It should be:

L3307 => 127.0.0.1:3306

Martin Prikryl

Posted 2017-08-23T14:28:34.810

Reputation: 13 764

I'm not receiving the SFTP error anymore, but after typing the password nothing happens – The One – 2017-08-23T14:46:55.457

Sounds good to me. What did you expect to happen? It just opened a tunnel (check PuTTY event log). Now you need to connect to the tunnel. – Martin Prikryl – 2017-08-23T14:50:47.233

Actually I might have not understood the question. What do you want to do with the tunnel? Why do you create a tunnel, if the workbench can create its own? – Martin Prikryl – 2017-08-23T14:51:46.120

I was expecting a confirmation like "Connection succesful" or something – The One – 2017-08-23T14:53:14.147

We need to connect to the database for development purposes, we must not create the tunnel inside the app, it must be created externally – The One – 2017-08-23T14:54:37.687

You can see that in the PuTTY event log. – Martin Prikryl – 2017-08-23T14:55:04.290

MySQL Workbench shows error when trying to connect directly to 127.0.0.1:3307 which makes me believe that the tunnel failed – The One – 2017-08-23T14:56:03.777

You have to connect to 3306. Ive already wrote that you have labeled 2 and 3 other way around. – Martin Prikryl – 2017-08-23T14:56:40.543

log doesn't show it – The One – 2017-08-23T14:57:13.080

Or actually you have to swap 3306 and 3307 in the PuTTY configuration - You have it wrong. – Martin Prikryl – 2017-08-23T14:57:38.977

So show us what does the log show. – Martin Prikryl – 2017-08-23T14:58:10.750

Updated the answer, let me do the swap – The One – 2017-08-23T15:10:36.213

1I have asked for PuTTY event log, not session log. Right click PuTTY console window title and select "Event log". – Martin Prikryl – 2017-08-23T15:13:06.030

Thanks Martin. It says Access Granted -> Local port 3306 forwarding to 127.0.0.1:3307 – The One – 2017-08-23T15:18:07.063

MySQL still can't connect, so I still have it wrong – The One – 2017-08-23T15:18:36.970

IT WORKS MARTIN, THANKS. It F****ing works! I'll update the question and mark your answer – The One – 2017-08-23T15:35:24.507