Vagrant: create entry for box in .ssh/config

Posted . Visible to the public.

If you want to ssh into your vagrant box without switching into the project directory and typing vagrant ssh, you can also create an entry directly in ~/.ssh/config. This will allow you to use ssh <my-box> from anywhere. Simply paste the information provided by vagrant ssh-config to your ~/.ssh/config-File: vagrant ssh-config >> ~/.ssh/config

Example:

$ vagrant ssh-config
Host foobar-dev
  HostName 127.0.0.1
  User vagrant
  Port 2200
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /home/daniel/project/myproject/vagrant/.vagrant/machines/foobar-dev/virtualbox/private_key
  IdentitiesOnly yes
  LogLevel FATAL

Background:

Vagrant Show archive.org snapshot is a tool that allows you to define a Virtual Machine (Image to use, network settings, shared folders to mount...) in a configuration file (Vagrantfile). It's also possible to directly provision the VM with a CMS like Puppet to have the machine in a desired state. Upon creation Vagrant will set up a new VM and add a SSH-Key so you can ssh into the machine. Normally you would switch to the directory containing the Vagrantfile and use the command line tool vagrant ssh to log in to your machine.

Daniel Straßner
Last edit
Daniel Straßner
License
Source code in this card is licensed under the MIT License.
Posted by Daniel Straßner to makandra dev (2017-08-16 08:01)