问题
Whenever I try to connect to my local Vagrant, I get this error when I run ssh vagrant@127.0.0.1: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?
回答1:
Make sure your vagrant is up and running by command : vagrant up
and then do vagrant ssh. It will connect to vagrant localhost
回答2:
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.
回答3:
Try command:
ssh -p 2222 vagrant@127.0.0.1
回答4:
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 :)
来源:https://stackoverflow.com/questions/28757642/vagrant-ssh-connect-to-host-127-0-0-12222-port-22-bad-file-number