Skip to content

Ssh Directly To Vagrant Without Vagrant Ssh

How to SSH directly to a vagrant box without using vagrant ssh#

You know you can ssh to vagrant with:

vagrant ssh

which is cool and all, but it doesn’t work like that in the real world.

The first thing you should do is ensure your vagrant box has its own private internal ip, which you can set in the vagrantfile: "private_network", ip: ""

Now we need to know how vagrant is doing the sshing

vagrant ssh-config

Now we know the user and the private key used to connect

$ vagrant ssh-config
Host default
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/stephen/lxd-terraform/.vagrant/machines/default/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL

Note: The port 2222 is not actually being used, it is 22

So we can create the following ssh connection:

ssh vagrant@ -i .vagrant/machines/default/virtualbox/private_key

This will hopefully connect you to your host

This won’t work if you are tunneling via another connection as you box is not connected to the internet