简体   繁体   中英

Vagrant SSH Tunnelling after using `vagrant ssh`

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?

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.

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 .

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. ;)

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM