Because the underlying technology Vagrant uses to create our development environment is the VM we can use the Secure Shell (or SSH) to administer our Unix based VMs. In this article, we’ll discuss how to use the built-in SSH tools of Vagrant.
The first command is
vagrant ssh-config. This will display the information about how we can use an SSH compatible client to connect to our VM.
our-awesome-project % vagrant ssh-config Host default HostName 127.0.0.1 User vagrant Port 2222 UserKnownHostsFile /dev/null StrictHostKeyChecking no PasswordAuthentication no IdentityFile /Users/scottkeck-warren/our-awesome-project/.vagrant/machines/default/virtualbox/private_key IdentitiesOnly yes LogLevel FATAL
The things to highlight in this output are the user “vagrant”, the port (2222), and the location of the IdentityFile which are all necessary when we’re setting up an SSH connection.
The next command of interest is the
vagrant ssh command. If we have an SSH client installed in the path of our command prompt Vagrant will use it to connect to our guest VM automatically. If we don’t or it’s not compatible with Vagrant we can still manually connect.
our-awesome-project % vagrant ssh Last login: Thu Feb 4 01:03:24 2021 from 10.0.2.2 vagrant@ubuntu2004:~$
In this article, we discussed how to use vagrant’s ssh-config command to get the connection information for an SSH client and how to use the built-in SSH command to connect to our vagrant development environment’s VM.
Scott is the Director of Technology at WeCare Connect where he strives to provide solutions for his customers needs. He's the father of two and can be found most weekends working on projects around the house with his loving partner.