plink's host key is not cached in the registry when run from perl on IIS/Windows

10,017

In a case like this, an application will often try to read the y/n response from the console (or in Unix speak, tty) and not necessarily from standard input, so the program is probably not registering the "y" response that you pipe to it.

Some workarounds might be:

  1. Run the command as the IIS user from the command-line. Maybe that will persist the host for the call from the webserver.
  2. Run the command from the command-line as yourself. Find your user's cache file and copy the key from that file into the administrator's cache file.
  3. If your webserver program has a console window on your machine, try accessing this script from a browser and then typing "y" into that console window when the script reaches the point where it is prompting you for this response (this probably won't work because the program might already be running in a child process, but it might be worth a try)
Share:
10,017
Guillaume Filion
Author by

Guillaume Filion

Updated on June 04, 2022

Comments

  • Guillaume Filion
    Guillaume Filion almost 2 years

    I'm trying to start a perl script on another server from a web page and I'm having problems with plink: it doesn't seem to remember the host key when run from the IUSR_ user.

    I managed to reduce the problem this:

    print "Content-Type:text/plain\n\n";
    open(PLINK, "| \"C:\\Program Files\\PuTTY\\plink.exe\" -pw sanitized Administrator\@serveurftp.a.b.c whoami") or die "Can't fork: $!";
    sleep(1);
    print PLINK "y\n";
    close(PLINK);
    

    When calling this script from a web page, I always get this:

    The server's host key is not cached in the registry. You
    have no guarantee that the server is the computer you
    think it is.
    The server's rsa2 key fingerprint is:
    ssh-rsa 2048 cb:eb:dc:1b:9e:1c:6b:fa:63:fb:2e:ba:2c:61:26:c4
    If you trust this host, enter "y" to add the key to
    PuTTY's cache and carry on connecting.
    If you want to carry on connecting just once, without
    adding the key to the cache, enter "n".
    If you do not trust this host, press Return to abandon the
    connection.
    Store key in cache? (y/n) serveurftp\administrator
    

    I should only be getting this on the first time, and only "serveurftp\administrator" afterwards, but it looks like plink can't store the host key when it's run from IIS.

    Do you guys have any idea on how to work around this?

  • Guillaume Filion
    Guillaume Filion over 13 years
    Do you know how I could do #1? On Unix I would do "sudo -u user plink..." but I don't know how do to the same on Windows...
  • mob
    mob over 13 years
    Go to Start >> All Programs >> Accessories and right-click on "Command Prompt". Select "Run as Administrator" or "Run as ..."
  • Rob Bajorek
    Rob Bajorek over 10 years
    Welcome to Stack Overflow. This link may theoretically answer the question, but it's preferable to include the essential parts of the answer here, and provide the link for reference.