Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 663
eComEvo Avatar asked Sep 17 '25 08:09

eComEvo


1 Answers

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.

like image 171
Angelos Avatar answered Sep 19 '25 15:09

Angelos