Set up an SSH tunnel as a Windows service using putty (plink)

The first time you access an SSH host, you’ll get and store the host key. Putty stores the host key in the registry. If you run putty plink as a Windows service, the host key should be available to the Windows system user. Otherwise, plink won’t connect to the remote server.

The solution is to obtain the host key from an interactive session then save it for use for the system user. Here are the steps:

1. Access the remote host interactively with putty or plink. Accept the host key.

2. Run regedit and export the key HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys. You’ll get something like this:
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys]
“rsa2@22:192.168.21.4″=”0×233. Edit the exported registry file, change HKEY_CURRENT_USER to HKEY_USERS\.DEFAULT:
[HKEY_USERS\.DEFAULT\Software\SimonTatham\PuTTY\SshHostKeys]
“rsa2@22:192.168.21.4″=”0×23,================================================

1. Install windows resource kit.

2. Install srvany as a service:

C:\tools\putty>instsrv ssh_tunnel “C:\Program Files\Windows Resource
Kits\Tools\srvany.exe”

3. Edit the following registry template to suite your environment:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\ssh_tunnel\Parameters]
“Application”=”C:\\tools\\putty\\plink.exe”
“AppDirectory”=”C:\\tools\\putty”
“AppParameters”=”-ssh -2 -L localhost:22:remotehost:22 -l userid -pw passwd 192.168.21.1 -N”

4. Import the registry entry.

5. Start the service with “net start ssh_tunnel” or from the services applet.

You may choose to use a batch file for srvany (instead of plink.exe), but you won’t be able to shut down the tunnel when you stop the service.

Also, if the Windows SYSTEM user cannot see the host key for SSH connection, the tunnel cannot be established.

::echo port
::plink.exe -R %1:127.0.0.1:%1 -pw X X@140.115.135.179
::echo y
regedit.exe /e moveRSA.reg HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys
::HKEY_USERS\.DEFAULT\Software\SimonTatham\PuTTY\SshHostKeys
instsrv sshclient c:\windows\system32\srvany.exe
echo Off
echo Windows Registry Editor Version 5.00 >> regService.reg
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\sshclient\Parameters] >> regService.reg
echo “Application"="C:\\windows\\system32\\plink.exe" >> regService.reg
echo “AppDirectory"="C:\\windows\\system32″ >> regService.reg
echo “AppParameters"="-ssh -2 -R %1:127.0.0.1:%1 -pw X X@140.115.135.179″ >> regService.reg
echo On
regService.reg
del regService.reg
net stop sshclient
net start sshclient

發表者:Admin

all u need that i can

有一則關於 Set up an SSH tunnel as a Windows service using putty (plink) 的留言

發表留言