This tutorial is going to cover shortly about running vagrant ssh on windows by different approaches. Probably, this will be useful when you want to use vagrant ssh command to ssh directly to your Vagrant box on Windows.
1. Problem and root cause
On Windows, SSH to a Vagrant box by running vagrant ssh command often throws an error as the following:
1 2 3 4 5 6 7 8 9 |
`ssh` executable not found in any directories in the %PATH% variable. Is an SSH client installed? Try installing Cygwin, MinGW or Git, all of which contain an SSH client. Or use your favorite SSH client with the following authentication information shown below: Host: 127.0.0.1 Port: 2222 Username: vagrant Private key: D:/Working/vagrant/centos7-3/.vagrant/machines/default/virtualbox/private_key |
The root cause could be because Vagrant could not found any SSH client in the Windows system path.
2. Solutions for running vagrant ssh on Windows
From the error log, Vagrant does recommend us 2 approaches for running vagrant ssh on Windows
Hence, in this article, we are going to get through both 2 approaches.
2.1. Install Git
Step 1. Download and install proper Git client for Windows from its website.
If you already installed Git, move to the step 2.
Step 2. Add the following paths in to the Windows system path.
- C:\Program Files\Git\cmd
- C:\Program Files\Git\mingw64\bin
- C:\Program Files\Git\usr\bin
To do that, you can do as below instructions:
- In Windows 7, right click on My Computer and select Properties > Advanced.
In Windows 8, Windows 10, go to Control Panel > System > Advanced System Settings > Environment Variables - Select the Path variable and append the above Git paths to the Path variable.
Here is an example on my Windows 10 machine.
Step 3. Verify again by executing the vagrant ssh command from the box directory. Here is my output of running vagrant ssh on windows
1 2 3 4 |
D:\Working\vagrant\centos7-3>vagrant ssh Last login: Mon Aug 29 13:28:00 2016 from 10.0.2.2 Welcome to your Vagrant-built virtual machine. [vagrant@localhost ~]$ |
2.2. Using Putty as a SSH client
Another way is to use a SSH client to ssh to the Vagrant box from Windows. And as you may know that Putty is a very popular SSH client for Windows. You can download a version on the Putty website.
After downloading, start Putty and review the recommendation of Vagrant again.
1 2 3 4 5 6 7 |
Or use your favorite SSH client with the following authentication information shown below: Host: 127.0.0.1 Port: 2222 Username: vagrant Private key: D:/Working/vagrant/centos7-3/.vagrant/machines/default/virtualbox/private_key |
First of all, it’s easy to see that we already had enough information to ssh to Vagrant box by using the provided private key. However, if we also know the password of the vagrant user, we will be able to ssh to the box using the password. As a result, we come up with 2 approaches to ssh to the Vagrant box with Putty as the following:
2.2.1. SSH to Vagrant box using password
This is the easiest way. If you know the password of the vagrant user, you just need to start Putty do following steps:
- Input the Host: 127.0.0.1, Port: 2222, Saved Session: Centos7
- Click Save button
- Click Open button
Input the following information.
- login as: vagrant
- vagrant@127.0.0.1’s password: [The vagrant’s password]
Then you should be logged in successfully.
2.2.2. SSH to Vagrant box using private key
2.2.2.1. Generate private key followed Putty format
The private key is located at the VM location. Here is an example on my machine.
1 |
Private key: D:/Working/vagrant/centos7-3/.vagrant/machines/default/virtualbox/private_key |
For this approach, you will have to download the PuTTY
- Start PuTTY
gen - Menu File –> Load Private key
- Browse to the Vagrant box private key (D:/Working/vagrant/centos7-3/.vagrant/machines/default/virtualbox/private_key)
- There will be a popup appeared to notify that the key was imported successfully
- Click OK to close the popup
- Click “Save private key” button to save the private key to Desktop with your desire name, for example: centos7pk
- Exit the PuTTY
gen
2.2.2.2. SSH to Vagrant box using Putty and new private key
Let’s review Vagrant recommendation again
1 2 3 4 5 6 7 |
Or use your favorite SSH client with the following authentication information shown below: Host: 127.0.0.1 Port: 2222 Username: vagrant Private key: D:/Working/vagrant/centos7-3/.vagrant/machines/default/virtualbox/private_key |
- Start Putty and input information as below:
- Select the Data tab and in the input “vagrant” for the field Auto-login username
- Expand the Connection node –> expand SSH –> select the Auth node.
- Browse to the key we have just generated above by PuTTY
gen.
- And click the Open button will get us logged in to the VM.
3. Summary
We have just learned how to run vagrant ssh on Windows. Because there is no SSH client on Windows by default, Vagrant cannot find and invoke the ssh command accordingly. Thefore, to fix that, we have to install a favorite one by ourselves. We also got through 2 approaches including to install Git with extra configuration of the Path and to use the Putty. If anyone is using Git, this approach should be very easy while the Putty approach takes more effort.
4. References
Install Vagrant on Ubuntu 16.04 LTS (Xenial Xerus)
How to Add a Vagrant Box from Local or Remote
Set Name, Number of CPUs, Memory and GUI Mode for Vagrant Virtual Machines