Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSH to Vagrant box in Windows?

People also ask

What is the command to change into vagrant box?

Command: vagrant box update This command updates the box for the current Vagrant environment if there are updates available. The command can also update a specific box (outside of an active Vagrant environment), by specifying the --box flag. Note that updating the box will not update an already-running Vagrant machine.

What is the command you used to establish connection to vagrant machine?

Command: vagrant ssh [name|id] [-- extra_ssh_args] This will SSH into a running Vagrant machine and give you access to a shell.


I use PuTTY to connect to my Vagrant boxes on Windows7.

Make sure you

  • convert the %USERPROFILE%\.vagrant.d\insecure_private_key to .ppk using PuTTYGen
  • use the .ppk key in your PuTTY session - configured in Connection > SSH > Auth > Private key file
  • use host 127.0.0.1
  • use port 2222 instead of 22
  • you can set the default username (vagrant) under Connection > SSH > Auth > Private key for authentication

You must patch some Vagrant code by modifying only one file, ssh.rb.

All the info is here: https://gist.github.com/2843680

vagrant ssh will now work also in Windows, just like in Linux.


EDIT: In newer Versions this became unnecessary. You still have to add the path to your ssh.exe to your PATH Variable:

Search for ssh.exe on your computer, copy the Path (i.e. C:\Program Files (x86)\Git\bin), open System Preferences, find the Environment variable Settings, click on the Path Variable, add the path, separating the existing paths using ;.


Another option using git binaries:

  1. Install git: http://git-scm.com/download/win
  2. Start Menu > cmd (shift+enter to go as Administrator)
  3. set PATH=%PATH%;C:\Program Files\Git\usr\bin
  4. vagrant ssh

Hope this helps :)

Just a bonus after months using that on Windows: use Console instead of the Win terminal, so you can always open a new terminal tab with PATH set (configure it on options)


Download Putty: http://www.chiark.greenend.org.uk/~sgtatham/putty/

Using putty.exe:

Putty GUI:

HostName: 127.0.0.1
Port: 2222

When you connect(Terminal Screen):

User: vagrant
Passwd: vagrant

Before you try to connect, verify your VM using cmd.exe:

 vagrant status

If it is down use:

vagrant up

The accepted answer is really helpful however it may happen that instead of the following key:

%USERPROFILE%\.vagrant.d\insecure_private_key

a different key has to be converted to the Putty's format:

{vagrant_machine_root}/.vagrant/machines/default/virtualbox/private_key

Where {vagrant_machine_root} is a folder with the Vagrantfile of the machine we want to connect to using Putty.

As @ibizaman mentioned use vagrant ssh-config to check what key is used by vagrant:

$ vagrant ssh-config
Host default
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile c:/dev/test/.vagrant/machines/default/virtualbox/private_key <-- HERE IS THE KEY YOU NEED TO CONVERT TO THE PUTTY FORMAT
  IdentitiesOnly yes
  LogLevel FATAL

Now you could also use the following plugin to connect using putty:

https://github.com/nickryand/vagrant-multi-putty

Just execute

vagrant plugin install vagrant-multi-putty

and make sure putty.exe and puttygen.exe are in your PATH

Then you'll be able to use

vagrant putty

The above mentioned executables are available from:

http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html


Either

  1. In your cmd console type the following:

    set PATH=%PATH%;C:\Program Files (x86)\Git\bin
    

OR

  1. Permanently set the path in your system's environment variables:

    C:\Program Files (x86)\Git\bin;