10

My MySQL client (Sequel Pro) is set up to connect to Vagrant over SSH. I've setup the following in my ~/.ssh/config file:

Host vagrant
  HostName 127.0.0.1
  CheckHostIP no
  Port 2222
  User vagrant
  IdentityFile ~/.vagrant.d/insecure_private_key

Everything works fine if I haven't run vagrant ssh. But once I've logged into the Vagrant box with that command Sequel Pro can no longer connect via SSH - it just says "The SSH Tunnel has unexpectedly closed." So I have to run vagrant reload before I can connect to the MySQL server.

Does anyone know how to get around this issue?

  • Your questions worked wonders for me when forwarding port 9001 from inside vagrant back to my local machine at 127.0.0.1 and port 9002 like `ssh -L 9002:127.0.0.1:9001 vagrant` – jmunsch Mar 11 '19 at 21:35

5 Answers5

22

I had the same problem, and it turned out to be an old key in my known_hosts file.

So, I did:

$ vi ~/.ssh/known_hosts

went to the line with 127.0.0.1:2200 on it, then did command dd to delete that line.
:x to save, and bam bob's yer uncle. Connection granted, long live Jambi.

I hope that saves someone some grief. Cheers.

Christian Giupponi
  • 7,408
  • 11
  • 68
  • 113
Ian Ring
  • 221
  • 2
  • 2
  • This did the trick for me! Thanks! Also note that if your vagrantfile specifies a `:private_network` ip address, you will also have to delete that line from `known_hosts` as well. "bam bob's yer uncle" -- love that. haha. – ctlockey Apr 28 '16 at 18:01
  • Up vote just for mentioning my uncle. He will be pleased. :) – Jack_Hu Sep 22 '18 at 03:24
15

I got around this issue by using port forwarding instead of SSH tunnelling. I added the following to Vagrantfile:

config.vm.network :forwarded_port, guest: 3306, host: 8306

Then connected to MySQL via port 8306.

  • This was the only solution which worked for me on a mac running el capitan. I had added the permissions to mysql; removed the `known_hosts` entry for `127.0.0.1` + re-added; edited `my.cnf` file to make various changes etc etc. Importantly though, this seems the correct solution. – wired00 Apr 26 '16 at 10:47
3

I had the similar issue. I struggled for whole day. I even went through Vagrant and Sequel Pro by Jeffrey Way. Still had a problem. I even changed forwarding port number in Vagrant file and did everything possible. But, the following saved my life.

When I did vagrant reload than I saw

  default: 22 => 2200 (adapter 1)

But, What I was doing was when setting up connection in sequel pro I had written SSH PORT: 2222 I did this based upon the video from the above link. But as soon as I changed to the number I saw with vagrant reload than it asked me for verification. I did select 'YES'. And, it did get connected. Happy ending after a day of struggle. Its for future readers,hopefully someone somewhere won't have to spend a day like me for this reason. ;)

score
  • 521
  • 1
  • 8
  • 22
  • For some reason I had it set to port 2222, I noticed in the config.yaml file it was pointing to 22, I changed it to port 22 in my sequel pro settings, then set it to my private_key file within the .vagrant/machines/default/virtualbox/ folder – Brad May 27 '15 at 20:38
1

Try to load the another key from folder with vagrant project
E.g. {vagrant_project}/.vagrant/machines/default/virtualbox/private_key

bbaf
  • 11
  • 1
0

In addition to the above, it could be one of the following problems:

  • The "insecure_private_key" is only used when the box is first brought up. Unless you've disabled the feature (insert_key=false), vagrant will replace that key with a randomly generated one, stored in .vagrant/machines/{machinename}/{providername}/private_key

    You can use that key in your ssh_config

  • Your MySQL settings are doing something different if the connection comes from localhost rather than from the "external" IP address.

Chris Cogdon
  • 7,481
  • 5
  • 38
  • 30