4

I have written a PS1 script that 7-zips a file and uses PuTTY's SCP to store it at my back-up server. I have tested it and it works perfectly.

Then I log into my SQL Server Agent and add an extra step to my back-up job to execute that script as soon as it's done with its back-up job. It's called correctly, the .7z file is created, and pscp.exe is called... and halts. I go to SQL Server Agent's Job Activity Monitor and find this:

Message
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 b5:f8:d2:5f:be:90:b6:be:15:d3:26:d5:c6:42:59:05
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)

Now this is a non-interactive session so I have no opportunity to press "y" there. On top of that, I have no idea which user this job is running on, and even if I knew that, I have no idea where this cache is. What now?

Liz Av
  • 464
  • 2
  • 6
  • 16

3 Answers3

5

You can do something like

echo n | pscp file.7z user@remote.tld:/path

Which allows the copy to continue without storing the key fingerprint in the registry. Alternatively you can

echo y | pscp file.7z user@remote.tld:/path

which will accept the question and add the key fingerprint to the users HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys.

Liz Av
  • 464
  • 2
  • 6
  • 16
user9517
  • 115,471
  • 20
  • 215
  • 297
  • 1
    I just tested and it works fine. It ended up at HKEY_USERS\S-1-5-18\Software\SimonTatham\PuTTY\SshHostKeys. Thanks. – Liz Av Feb 15 '12 at 13:20
3

After you added the SSH fingerprint in your local session you can also go to your Registry at

HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys

and copy the keys to other users, e.g.

HKEY_USERS\.DEFAULT\Software\SimonTatham\PuTTY\SshHostKeys

or for Local System User:

HKEY_USERS\S-1-5-18\Software\SimonTatham\PuTTY\SshHostKeys
  • 1
    Excellent answer, thank you – reformed May 12 '23 at 18:52
  • Both answers are very good solutions to the problem, but I realized I should have switched the accepted answer to this one because it most directly answers the question as stated. – Liz Av May 25 '23 at 16:43
0

Add the option -batch to your script file.

Liz Av
  • 464
  • 2
  • 6
  • 16
Miguelite
  • 19
  • 1