Explicitly ssh into vagrant machine

Neeraj Singh

By Neeraj Singh

on December 27, 2015

After building vagrant machine the command to ssh into the guest machine is pretty simple.

1vagarnt ssh

While working with chef I needed to explicitly ssh into the vagrant machine. It took me sometime to figure it out.

The key is command vagrant ssh-config. The output might look like this.

1$ vagrant ssh-config
2Host vmachine
3  HostName
4  User vagrant
5  Port 2222
6  UserKnownHostsFile /dev/null
7  StrictHostKeyChecking no
8  PasswordAuthentication no
9  IdentityFile /Users/nsingh/code/vagrant-machine/.vagrant/machines/vmachine/virtualbox/private_key
10  IdentitiesOnly yes
11  LogLevel FATAL
12  ForwardAgent yes

Open ~/.ssh/config and paste the output at the end of the file and save the file.

Now I can ssh into vagrant machine using ssh command as shown below.

1ssh vmachine

If you are wondering from where the name vmachine came then this is the name I had given to my vagrant machine .