We saw that we can ssh into our vagrant virtual machine in the post Add SSH Public Key to Vagrant:

$ ssh -i ~/.ssh/id_rsa.pub -p 2222 vagrant@localhost

However it is too long to type, right? And if you ssh into a server you should remember the IP, like 173.108.251.102. There should be an easy way to do that since we all are lazy developers (?).

The ssh program on a host receives it’s configuration from either the

  1. cli (as we’ve seen above),
  2. /etc/ssh/ssh_config file for global-scope,
  3. ~/.ssh/config file for user-scope.

These files are formatted like below:

For our local vagrant machine:

Host vagrantlocal
  HostName localhost
  Port 2222
  User vagrant
  IdentityFile ~/.ssh/id_rsa.pub
  PasswordAuthentication no

For a remote server:

Host myremoteserver
  HostName 173.108.251.102
  User user
  IdentityFile ~/.ssh/id_rsa.pub
  PasswordAuthentication no

And then you can access them via ssh:

# vagrant virtual machine
$ ssh vagrantlocal

# remove server
$ ssh myremoteserver

You can see more configuration file options at Configuration Options.

All done!