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:
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:
config.vm.network "private_network", ip: "192.168.33.10"
Now we need to know how vagrant is doing the sshing
Now we know the user and the private key used to connect
$ vagrant ssh-config Host default HostName 127.0.0.1 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 email@example.com -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