Ssh – Can’t SSH into a Vagrant Virtual Machine

configurationlocalhostport-forwardingsshvagrant

Local Vagrant machine installed at IP address 10.0.0.23 with hostname lamp-vm.

Using vagrant ssh command, I can connect just fine and do everything I need.

This creates an error

$ ssh vagrant@lamp-vm -v -v

debug1: connect to address 10.0.0.23 port 22: Connection timed out
ssh: connect to host lamp-vm port 22: Connection timed out

My /etc/hosts file contains 10.0.0.23 lamp-vm.

My .ssh/config file looks like

Host lamp-vm
User vagrant
IdentityFile ~/.ssh/vagrant

I have tried the ssh command with and without the -i /path/to/.sh/identity_file as well.

How do I connect to my Vagrant Virtual Machine using SSH?

Best Answer

It's old but as there is no answer, I'll provide one. Command:

vagrant ssh

Is the equivalent of

ssh vagrant@localhost -p 2222 -i .vagrant/machines/default/virtualbox/private_key

This is default behavior, if you changed something change command appropriately. First of all Vagrant will create vagrant user on your guest box, and you will use that user to ssh. As previous folks said, it will forward traffic from port 2222 on your host to port 22 on your guest, by default (when you use vagrant up, you see that message being displayed). And lastly Vagrant creates keys for ssh session so you don't have to, so you need to provide public key as argument when connection via ssh.