Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Local Vagrant machine installed at IP address 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 port 22: Connection timed out
ssh: connect to host lamp-vm port 22: Connection timed out

My /etc/hosts file contains 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

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
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:

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

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.


# Setting up private_network to have virtual host :private_network, ip: ""

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

ssh into machine:

ssh vagrant@

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

vagrant@'s password:

And boom, you're in!

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

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

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

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:

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

share|improve this answer

Your Answer


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.