Skip to content

Instantly share code, notes, and snippets.

@acoulton
Created September 14, 2016 10:16
Show Gist options
  • Save acoulton/aa0ea4bdc7be589a83b7fef6eed7478d to your computer and use it in GitHub Desktop.
Save acoulton/aa0ea4bdc7be589a83b7fef6eed7478d to your computer and use it in GitHub Desktop.
Launch putty for a vagrant machine, including converting key with winscp
@echo off
echo Launching Putty SSH connection to vagrant in %cd%
set VAGRANT_DIR=%cd%\.vagrant\machines\default\virtualbox
IF NOT EXIST %VAGRANT_DIR% goto novagrant
echo Locating vagrant forwarded SSH port
vagrant port --guest 22 > "%VAGRANT_DIR%\ssh_port"
if %errorlevel% neq 0 goto error
set /p SSH_PORT=<"%VAGRANT_DIR%\ssh_port"
if %errorlevel% neq 0 goto error
echo Forwarded port is %SSH_PORT%
echo Converting Vagrant private key to putty key
"C:\Program Files (x86)\WinSCP\WinSCP.com" /keygen "%VAGRANT_DIR%\private_key" /output="%VAGRANT_DIR%\private_key.ppk"
if %errorlevel% neq 0 goto error
echo Launching putty
start "" "C:\Program Files (x86)\PuTTY\putty.exe" -ssh [email protected] %SSH_PORT% -i "%VAGRANT_DIR%\private_key.ppk"
if %errorlevel% neq 0 goto error
exit /b 0
:novagrant
echo No vagrant directory in %VAGRANT_DIR% - have you got a running machine here?
exit /b 9
:error
echo Command failed with error %errorlevel%
exit /b %errorlevel%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment