How to: Set Up SSH Handler on Windows

    [Updated: Jun 27, 2018]

    Change Log:

    • Updated batch script for VIRL 1.2.x
    • Minor edits
    • Fixed Windows registry file's quotes
    • A more complex ssh URL processing is required for putty.

     

     

    Summary

    In upcoming releases of VIRL, the user will be able to launch an external terminal directly from UWM. This will allow the user to interact with the simulation nodes without having to open VM Maestro. The user will be able to connect to ssh and telnet sessions by clicking on a link in UWM for the desired node.

     

    Getting Started

    Follow this step-by-step guide to configure PuTTY as your native SSH Session handler on Windows.



    Note: this example is designed for PuTTY but can be adapted for other applications.


     

    The function of the SSH handler is highly dependent on the location of the PuTTY executable; which is referenced both in the registry file as well as in the putty_util.bat file. Verify the exact location (directory path) of putty.exe on your system. Most current browsers will place downloads in your Download(s) folder or directory. If you do not move putty.exe from that location, the session handler will not work. Here is a more elaborate script on Github that can overcome putty.exe location problems using Visual Basic. In some cases, this may be your only option for a fully functional SSH handler.

     


    CAUTION:

    This requires editing your registry. It is HIGHLY recommended to make a backup of your computer or registry prior to continuing.


     

    Back-up Windows Registry

    You can create a copy of your running registry by doing the following:

     

    Windows 7 and later

    1. Click Start, type regedit.exe in the search box, and then press Enter
    2. In Registry Editor, click File > Export
    3. In the Export Registry File box, select the location where you want to save the backup copy, name your back up file and click save

     

    Download PuTTY

     

    Register SSH Protocol

    • Go to the location of putty.exe, in this example C:/Program Files/putty
    • Open Notepad.exe and then paste the following text into the new document

     

    REGEDIT4
    [HKEY_CLASSES_ROOT\ssh]
    @="URL:Putty SSH Protocol"
    "URL Protocol"=""
    [HKEY_CLASSES_ROOT\ssh\shell]
    [HKEY_CLASSES_ROOT\ssh\shell\open]
    [HKEY_CLASSES_ROOT\ssh\shell\open\command]
    @="\"C:\\Program Files\\putty\\putty_util.bat\" \"%1\""
    [HKEY_CLASSES_ROOT\telnet] @="URL:Putty Telnet Protocol"
    "URL Protocol"=""
    [HKEY_CLASSES_ROOT\telnet\shell]
    [HKEY_CLASSES_ROOT\telnet\shell\open]
    [HKEY_CLASSES_ROOT\telnet\shell\open\command]
    @="\"C:\\Program Files\\putty\\putty_util.bat\" \"%1\""
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    


    • Save the file in C:/Program Files/putty and name it ssh.reg
      NOTE: make sure to change 'Save as' type to ( * . * )
    • With Notepad still open, create new document and paste the following text. It needs to process the ssh URL into format supported by putty, hence the somewhat complex code.


    @echo off
    SETLOCAL ENABLEDELAYEDEXPANSION
    
    SET addr=%1
    :: Drop double quotations from input
    SET addr=%addr:"=%
    :: Drop trailing slash (if present)
    IF %addr:~-1%==/ SET addr=%addr:~0,-1%
    
    :: Extract 'ssh://' schema because it causes problems with usernames in PuTTY
    SET schema=%addr:~0,6%
    IF %schema%==ssh:// (
     :: Drop ssh:// schema from beggining of connection string
     SET schemaless=%addr:~6%
      :: PuTTy does not work well with ssh and port specified in format '<IP_ADDR>:<PORT>' so we split it to '<IP_ADDR> <PORT>'
     :: Split connection_string into credentials and host
     FOR /F "tokens=1,2 delims=@" %%a in ("!schemaless!") DO (
     SET credentials=%%a
     SET host=%%b
     )
    
     IF NOT "!credentials!"=="" (
     IF NOT "!host!"=="" (
     SET credentials="!credentials!@"
     ) ELSE (
     SET host=!credentials!
     SET "credentials="
     )
     )
    
     :: Detect whether we deal with IPv4 or IPv6
     echo !host!|findstr /r /c:"\[*.\]" >nul
    
     :: Replace port delimiter':' in address with blank space
     IF errorlevel 1 (
     :: IPv4
     SET host=!host::= !
     ) ELSE (
     :: IPv6
     SET host=!host:]:=] !
     )
    
     :: Concat credentials and host parts back together
     SET "conn_string=!credentials!!host!"
    ) ELSE (
     SET conn_string=%addr%
    )
    
    ECHO %conn_string%
    "C:\Program Files\PuTTY\putty.exe" %conn_string%
    
    

     

    • Save the to same location as ssh.reg and name it putty_util.bat
      CAUTION:  Back-up your computer or registry prior to continuing
    • Right click on newly created file ssh.reg and click on Merge.
    • Answer the prompt to allow the change and wait for confirmation dialog to appear.
    • Once completed click OK to close confirmation dialog window.
    • (Recommended) Close all documents and save your work, then reboot your computer.
    • Click on this link (ssh://127.0.0.1) and PuTTY should try to connect to localhost.