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
18.104.22.168. 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
cli(as we've seen above),
/etc/ssh/ssh_configfile for global-scope,
~/.ssh/configfile 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 22.214.171.124 User user IdentityFile ~/.ssh/id_rsa.pub PasswordAuthentication no
And then you can access them via
# vagrant virtual machine $ ssh vagrantlocal # remove server $ ssh myremoteserver
You can see more configuration file options at Configuration Options.