How to run a putty ssh tunneling as Windows service?

9,479

Windows services must be specially written to respond to the Service Manager's control requests. You cannot use any random executable as binPath; you'll have to use srvany or similar tools.

You should also use the command-line plink instead of putty, since the latter might not work properly as a service.

Finally, note that PuTTY sessions are per-user, stored in your Windows profile. Services normally run under special accounts, using the SYSTEM profile. You'll have to change the service to run under your own account, or configure the session in the SYSTEM profile as well (psexec -dsi putty).

Share:
9,479

Related videos on Youtube

Chau Chee Yang
Author by

Chau Chee Yang

Updated on September 18, 2022

Comments

  • Chau Chee Yang
    Chau Chee Yang over 1 year

    In Windows XP or above, I may run a shell command

    putty.exe -load ssh_tunnel
    

    to start a ssh session configured as ssh tunneling.

    I want to ssh tunnel session become available when my computer start without logon to any user session.

    Keep the shell command in Windows service seems to be the only solution. I try create a service:

    c:\> sc create ssh_tunnel binpath="c:\putty.exe -load ssh_tunnel
    [SC] CreateService SUCCESS
    

    The service created successfully. When I start the service:

    C:\>sc start ssh_tunnel
    [SC] StartService FAILED 1053:
    
    The service did not respond to the start or control request in a timely fashion.
    

    It doesn't start.

  • Chau Chee Yang
    Chau Chee Yang about 12 years
    Thanks. I face problems using the srvany in dynamic IP environment and it is not practical to go ahead with the Putty as service solution. I finally decide to use plink to perform the ssh connection.
  • Sopalajo de Arrierez
    Sopalajo de Arrierez almost 10 years
    Could you please expand about the solution? I am using plink for the same, but I still get service not responding to control request. I receive some net helpmsg 2186 that is not very helpful.
  • user1686
    user1686 almost 10 years
    @SopalajodeArrierez: Are you using plink through srvany or directly?
  • user1686
    user1686 almost 10 years
    @SopalajodeArrierez: Ah, yes, a service would not have access to your network credentials. (Although it could be configured to run under a specific account, rather than the generic one.)