Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

6 Answers 6

This behavior is by design.

Vagrant uses VirtualBox NAT mode which means using port forwarding.

You can't SSH directly to your VM using NAT mode.

Using 'vagrant ssh' means vagrant will do the port forwarding for you so you don't have to worry about it. I think it will connect to localhost on port 2222 by default but it will try to also sort out any port number collisions.

If you need to SSH directly to your VM, switch the VM into host-only or bridged networking mode.

share|improve this answer
    
Thanks Philip but how would I go about solving that? Sorry for the inexperience. –  csi Oct 23 '12 at 16:41
1  
I am using host-only mode and the problem persists. –  csi Oct 23 '12 at 17:01

I would have added this as a comment, but I currently do not have enough rep to do so. I've written a how-to for setting your VM to bridged mode here:

http://askubuntu.com/questions/116861/setting-up-a-network-between-a-host-and-guest-virtual-machine/116909#116909

I hope you find this useful!

share|improve this answer
    
+1 here and on AU.SE; nice write-up. –  msanford Oct 23 '12 at 18:25

Can you ping the VM Christopher? It defiantly sounds like a small networking issue. Were you able to set it for bridge networking mode?

share|improve this answer

I faced this problem too and this was my final configuration that allowed me to ssh into my vagrant machine from anywhere in my host machine.

Vagrantfile:

...
# Setting up private_network to have virtual host
config.vm.network :private_network, ip: "192.168.33.10"

# Enable ssh forward agent
config.ssh.forward_agent = true
...

ssh into machine:

ssh vagrant@192.168.33.10

You will be prompted for password(default is vagrant):

vagrant@192.168.33.28's password:

And boom, you're in!

PS* You can use scp too anywhere in your host machine:

scp /path/to/src/file vagrant@192.168.33.10:/path/to/destination/file
share|improve this answer

Destroyed the virtual machine
Reloaded the virtual machine
Everything worked

Not sure why but obviously something didn't load properly on the first provisioning.

share|improve this answer

Check out this comment: https://github.com/mitchellh/vagrant/issues/1936#issuecomment-21139674

Basically, even when using private networking, vagrant still does ssh on 127.0.0.1. Try that ssh command @127.0.0.1 instead of your private ip/hostname.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.