Automating Putty

Automating Putty

We could make a saved session of putty in registry.

  • convert the %HOMEPATH%.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 port 2222 instead of 22

All previously installed packages are in %UserProfile%\AppData\Local\NuGet\Cache\vagrant.0.8.0.nupkg

How vagrant Chocolatey installs putty support:

#Set putty registry keys to work with vagrant $path = “HKCU:\Software”,"\SimonTatham","\PuTTY","\Sessions","\vagrant" $publicKeyFile = “C:\jruby-1.6.4\lib\ruby\gems\1.8\gems\vagrant-0.8.7\keys\vagrant.ppk” $vagrantKey = ""

foreach ($key in $path) { $vagrantKey += $key if (-not (Test-Path $vagrantKey)) { New-Item -type Directory $vagrantKey } }

New-ItemProperty $vagrantKey -propertyType String -name “HostName” -value “vagrant@localhost” -force New-ItemProperty $vagrantKey -propertyType dword “PortNumber” -value “2222” -force New-ItemProperty $vagrantKey -propertyType String “Protocol” -value “ssh” -force New-ItemProperty $vagrantKey -propertyType String “Protocol” -value “$publicKeyFile” -force gem install vagrant-putty vagrant putty

Note: Don’t forget to convert private key to Putty format (.ppk) with puttygen.exe tool.


c:\Program Files (x86)\Putty\putty.exe -load Vagrant -pw vagrant


Vagrant & Putty

require ‘rubygems’

module VagrantPutty class Command < Vagrant::Command::Base register “putty”, “PuTTY into the VM environment”

def execute
  system("putty vagrant@localhost -i #{self.class.ppk_path} -P 2222")

def self.ppk_path
  File.join Gem.loaded_specs['vagrant'].full_gem_path, "keys", "vagrant.ppk"

end end

There is a environment variable:

GIT_SSH=c:\Program Files (x86)\Putty\plink.exe

Don’t use it. Now you know better.


Add path to Putty to system: set PATH=%PATH%;%PROGRAMFILES(X86)%\Putty setx PATH “%PATH%” /m

Vagrant and SSH (from GIT)

Make Vagrant work again with SSH. SSH comes with GIT, in it’s /bin directory.

Find out where GIT is: where git

And, add ../bin to the global path: set PATH=%PATH%;%PROGRAMFILES(X86)%\Git\bin setx PATH “%PATH%” /m

Now, typing: where ssh

Will give you something.

Now, just apply changes in vagrant file: vagrant\ssh.rb (vagrant\embedded\lib\ruby\gems\1.9.1\gems\vagrant-1.0.3\lib\vagrant\ssh.rb)

Source: :: Get SSH working on Vagrant/Windows/Git — Gist

Now, will work again: vagrant ssh

date 01. Jan 0001 | modified 28. May 2021
filename: Putty & SSH