I created a Vagrant Box, played with it, made some custom dev.
But then I wanted to login without playing "vagrant ssh myvagrantbox".
For that I appended the "~/.ssh/id_rsa.pub" from my host to the autorised keys of myvagrantbox.
Then I made a "Vagrant halt" / "vagrant up".
But now Vagrant says it cannot connect because of a timeout.
Vagrant says "myvagrantbox" is running but I can't connect with "vagrant ssh myvagrantbox".
Any idea ?
A better solution than destroying, beginning from zero again ?
Enable the GUI mode, as your box might be stuck at the bootloader.
For this just add this to your Vagrantfile :
config.vm.provider :virtualbox do |vb|
vb.gui = true
end
To complete what I wanted to do:
I wanted to connect to my Vagrant box with ssh, without playing "vagrant ssh myvagrantbox".
The solution was quite simple:
ssh vagrant#127.0.0.1 -p 2222 -i ~/.vagrant.d/insecure_private_key
Vagrant uses ssh by default on port 2222 and not port 22. I was forgotting the port and was stuck with a password.
Hopes this will help someday...
Related
I have this weird problem where "vagrant up" times out:
$ vagrant up
...
default: SSH username: vagrant
default: SSH auth method: private key
Timed out while waiting for the machine to boot.
but "vagrant ssh" works:
$ vagrant ssh
...
vagrant#vagrant-ubuntu-trusty-64:~$
I have tweaked my "config.vm.boot_timeout" to an absurdly high number just to make sure that isn't the issue.
I'm not sure how to debug this. I've read a bunch of articles demonstrating how to get ssh working with vagrant, but if that were my problem then "vagrant ssh" shouldn't work, right? Why does "vagrant up" not work?
I'm not sure what the problem was, but generating a new key pair has fixed it.
I currently use Vagrant and Chef to provision a VM and setup my PHP based project. This includes running composer install which essentially does a git clone of a number of private repositories.
After setting up ssh agent forwarding as outlined in the docs and the answers here: How to use ssh agent forwarding with "vagrant ssh"? I have successfully got it working.
The problem I'm having is when ever I boot a VM, provision a VM or SSH into a VM I'm now asked for vagrants default password, see examples below:
==> web: Waiting for machine to boot. This may take a few minutes...
web: SSH address: 192.168.77.185:22
web: SSH username: vagrant
web: SSH auth method: private key
Text will be echoed in the clear. Please install the HighLine or Termios libraries to suppress echoed text.
vagrant#192.168.77.185's password:
Example 2
➜ vagrant git:(master) ✗ vagrant ssh
vagrant#192.168.77.185's password:
This is pretty inconvenient as I work across a number of projects, including destroying and creating some a number of times a day (Chef test kitchen). Is there anyway to automatically use my public key as well so I don't need to continually enter a password?
I ran into a similar issue recently after creating a new Vagrant box from scratch. The problem turned out to be old entries in ~/.ssh/known_hosts (on OS X).
Try the following (assumes OS X or linux):
ssh into your Vagrant machine
type ip addr or ifconfig or the like (depending on your OS)
take note of the IP addresses listed, including 127.0.0.1
on your host machine, run ssh-keygen -R {vm-ip-address} (make sure to include 127.0.0.1 and [127.0.0.1]) for the addresses in step 3
confirm the relevant entries have been removed from ~/.ssh/known_hosts
vagrant reload
vagrant ssh
Alternatively, you can just delete/move/rename the ~/.ssh/known_hosts file, though this will require reconfirming authenticity again for multiple machines you've already ssh'd to.
I hope that helps.
Reference: http://www.geekride.com/ssh-warning-remote-host-identification-has-changed/
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?
Try command:
ssh -p 2222 vagrant#127.0.0.1
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.
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 :)
Make sure your vagrant is up and running by command : vagrant up
and then do vagrant ssh. It will connect to vagrant localhost
I do not understand why I cannot "vagrant up" anymore after I run some provisioning scripts (I use ansible).
[default] Waiting for machine to boot. This may take a few minutes...
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.ssh.timeout" value) time period. This can
mean a number of things.
If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.
If the box appears to be booting properly, you may want to increase
the timeout ("config.ssh.timeout") value.
What can be broken? What is vagrant trying to do when running vagrant up?
Connecting with the default user, i.e. "vagrant" ?
Obviously it is related to SSH.
Yes I pushed some SSH keys but I do not think I changed the vagrant user at all so "vagrant up" should still work right? I also changed a little bit the /etc/sudoers file but I tried without modifying it and it does not seem to work anyway...
Well, I am running out of ideas..
Thanks.
My 2 cents
Set vbox.gui to true in your Vagrantfile, this will help you to see if the box is booted correctly. It cloud get stuck during the boot process, however, vagrant is expecting an exit code from it, it timed out and you get what you saw.
After seeing the error message, run vagrant ssh and see what you get.
NOTE: you may need to enable debug to see more info: VAGRANT_LOG=debug vagrant up
BTW: make sure your vagrant (1.3.5) + VirtualBox (4.3.2) stays current.
Actually, this might not be an SSH issue. It sounds like your VM is hanging when you vagrant up and it may be the result of networking issues that can be cleared by restarting the networking when on your VM. Try the steps below to fix.
First, edit your Vagrantfile and add vb.gui = true to bring up your VM in a GUI mode. For example, my test Vagrantfile looks like:
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "testbox"
config.vm.network :private_network, ip: "192.168.50.102"
config.vm.provider :virtualbox do |vb|
vb.gui = true
end
end
Second, issue a vagrant up and your VM GUI will appear. Your vagrant will still hang but you should be able to log into your VM box via the GUI.
Third, open a terminal window and issue the following command:
sudo /etc/init.d/network restart
This should resolve your issue. You could issue a vagrant reload to refresh the VM.
Here's a reference to the vagrant hanging issue: https://github.com/mitchellh/vagrant/wiki/%60vagrant-up%60-hangs-at-%22Waiting-for-VM-to-boot.-This-can-take-a-few-minutes%22
(Note, my VM was a CentOS / VirtualBox instance.)
Starting a 64-bit vagrant box in a host not supporting virtualization leads to this error, you will see it if you start the VM in GUI mode.
I am using bento/ubuntu-16.04 and following steps solved my problem.
You need to change the following in
i. Go to this directory: cd ~/.vagrant.d/boxes/bento-VAGRANTSLASH-ubuntu-16.04/2.3.1/virtualbox
ii. Open box.ovf file using nano box.ovf
iii). Change <Adapter slot="0" enabled="true" MACAddress="080027C30A85" type="82540EM">
To
<Adapter slot="0" enabled="true" MACAddress="080027C30A85" cable="true" type="82540EM">
You might need to reboot your machine. To reboot follow these steps.
i. vagrant halt
ii. vagrant up
iii. vagrant ssh
Rather than create a new SSH key pair on a vagrant box, I would like to re-use the key pair I have on my host machine, using agent forwarding. I've tried setting config.ssh.forward_agent to TRUE in the Vagrantfile, then rebooted the VM, and tried using:
vagrant ssh -- -A
...but I'm still getting prompted for a password when I try to do a git checkout. Any idea what I'm missing?
I'm using vagrant 2 on OS X Mountain Lion.
Vagrant.configure("2") do |config|
config.ssh.private_key_path = "~/.ssh/id_rsa"
config.ssh.forward_agent = true
end
config.ssh.private_key_path is your local private key
Your private key must be available to the local ssh-agent. You can check with ssh-add -L, if it's not listed add it with ssh-add ~/.ssh/id_rsa
Don't forget to add you public key to ~/.ssh/authorized_keys on the Vagrant VM. You can do it copy-and-pasting or using a tool like ssh-copy-id
Add it to the Vagrantfile
Vagrant::Config.run do |config|
# stuff
config.ssh.forward_agent = true
end
See the docs
In addition to adding "config.ssh.forward_agent = true" to the vagrant file make sure the host computer is set up for agent forwarding. Github provides a good guide for this. (Check out the troubleshooting section).
I had this working with the above replies on 1.4.3, but stopped working on 1.5. I now have to run ssh-add to work fully with 1.5.
For now I add the following line to my ansible provisioning script.
- name: Make sure ssk keys are passed to guest.
local_action: command ssh-add
I've also created a gist of my setup: https://gist.github.com/KyleJamesWalker/9538912
If you are on Windows, SSH Forwarding in Vagrant does not work properly by default (because of a bug in net-ssh). See this particular Vagrant bug report: https://github.com/mitchellh/vagrant/issues/1735
However, there is a workaround! Simply auto-copy your local SSH key to the Vagrant VM via a simple provisioning script in your VagrantFile. Here's an example:
https://github.com/mitchellh/vagrant/issues/1735#issuecomment-25640783
When we recently tried out the vagrant-aws plugin with Vagrant 1.1.5, we ran into an issue with SSH agent forwarding. It turned out that Vagrant was forcing IdentitiesOnly=yes without an option to change it to no. This forced Vagrant to only look at the private key we listed in the Vagrantfile for the AWS provider.
I wrote up our experiences in a blog post. It may turn into a pull request at some point.
Make sure that the VM does not launch its own SSH agent. I had this line in my ~/.profile
eval `ssh-agent`
After removing it, SSH agent forwarding worked.
The real problem is Vagrant using 127.0.0.1:2222 as default port-forward.
You can add one (not 2222, 2222 is already occupied by default)
config.vm.network "forwarded_port", guest: 22, host:2333, host_ip: "0.0.0.0"
"0.0.0.0" is way take request from external connection.
then
ssh -p 2333 vagrant#192.168.2.101 (change to your own host ip address, dud)
will working just fine.
Do thank me, Just call me Leifeng!
On Windows, the problem is that Vagrant doesn't know how to communicate with git-bash's ssh-agent. It does, however, know how to use PuTTY's Pageant. So, as long as Pageant is running and has loaded your SSH key, and as long as you've set config.ssh.forward_agent, this should work.
See this comment for details.
If you use Pageant, then the workaround of updating the Vagrantfile to copy SSH keys on Windows is no longer necessary.