eComEvo
eComEvo

Reputation: 12599

Vagrant ssh connect to host 127.0.0.1:2222 port 22: Bad file number

Whenever I try to connect to my local Vagrant, I get this error when I run ssh [email protected]:2222 from the Windows git bash:

ssh: connect to host 127.0.0.1:2222 port 22: Bad file number

It was working previously, so I'm not sure what could have caused this. When I try to do an SFTP connection in PHPStorm 8, I get this error:

Connection to '127.0.0.1' failed.
SSH_MSG_DISCONNECT: 2 Too many authentication failures for vagrant 

I've tried vagrant destroy with vagrant box remove laravel/homestead and then recreating the box from a backup I had that previously worked using vagrant box add laravel/homestead homestead.box but I still get the same errors.

I'm on Windows 7.

What can I do to get access to my vagrant box commandline again?

Upvotes: 4

Views: 12207

Answers (5)

ArleeVillarivera
ArleeVillarivera

Reputation: 1

  • Make sure vagrant is up and running by using the command: vagrant status.
  • We also need to check the ssh config of vagrant by running the
    command vagrant ssh-config.

Upvotes: 0

Angelos
Angelos

Reputation: 237

The answer by outboundexplorer above is the correct one I believe.
Here is my step-by-step approach on how I did this:

Step 1: Find out exactly what SSH settings to use

Ensure the vagrant box is running (you've done vagrant up that is)

From the command line, go to your project directory (the one where the Vagrantfile is located) and run vagrant ssh-config.

You'll get an output like this:

Host default
    HostName 127.0.0.1
    User ubuntu
    Port 2222
    UserKnownHostsFile /dev/null
    StrictHostKeyChecking no
    PasswordAuthentication no
    IdentityFile C:/Projects/my-test-project/.vagrant/machines/default/virtualbox/private_key
    IdentitiesOnly yes
    LogLevel FATAL

Step 2: Setting up PHPStorm to SFTP to the Vagrant box

Based on the config settings shown above, I set up the following SFTP remote deployment server:

  • SFTP host: 127.0.0.1
  • Port: 2222
  • Root path: /home/ubuntu/my-test-project (this is the folder inside the Vagrant box where the files will be uploaded to, change to whatever suits your needs)
  • User name: ubuntu
  • Auth type: Select "Key pair (OpenSSH or PuTTY)"
  • Private key file: Point to the IdentityFile path shown (C:/Projects/....)

... and that was it.

Upvotes: 4

andy_roddam
andy_roddam

Reputation: 461

I got this same failure when using PHpStorm to SSH into the VirtualBox guest machine that i had set up with Vagrant. Everything worked fine before I upgraded to Windows 10. After upgrading, first of all i had to upgrade to VirtualBox and Vagrant latest versions to get everything to work on Windows 10.

But then i couldn't ssh into the guest machine using the PhpStorm ssh client. After much reading, everything seemed to suggest that I had too many ssh-keys installed on my Windows machine, but checking regedit just showed that I only had a couple of keys which should be less than the suggested max 5 keys (as default). In the end i did vagrant ssh which didn't allow me to ssh into the guest machine, but it did reconfirm the ssh details for me. I then realized that after all the new installs it didn't want me to use the C:\Users\Andy\.vagrant.d\insecure_private_key key but instead use a key that it had placed within the project itself at C:/Users/Andy/CodeLab5/vagrant/.vagrant/machines/default/virtualbox/private_key.

Everything is working as it should again now :)

Upvotes: 1

aflorezd
aflorezd

Reputation: 2770

Try command:

ssh -p 2222 [email protected]

Upvotes: 3

Enigma
Enigma

Reputation: 859

Make sure your vagrant is up and running by command : vagrant up

and then do vagrant ssh. It will connect to vagrant localhost

Upvotes: 0

Related Questions