1

I saw a solution to cache a server host key by adding the command just below on the top of my script before running the other Plink tasks.

& "echo y | C:\Program Files\PuTTY\plink.exe" -ssh -batch -i $PrivateKeyPath $username "exit" 2>&1

Error message:

The term 'echoy| C:\ProgramFiles\PuTTY\plink.exe' is not recognized as the name of a cmdlet,...

So the spaces prior the pipe symbol are removed and therefore the command is not recognized.

My other attempt is to use Start-Process but I do not know how I am able to prepend echo y | to the plink.exe path.

Start-Process -FilePath 'C:\Program Files\PuTTY\plink.exe' -Argumentlist "-ssh -batch -i $PrivateKeyPath $username $command 2>&1"

Is there an option to prepend something to the -FilePath?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Alex_P
  • 2,580
  • 3
  • 22
  • 37

2 Answers2

2

Do not blindly answer "y" to Plink host key verification prompt. You lose a protection against man-in-the-middle attacks.

You should use the -hostkey switch with your host key fingerprint.

Similarly for pscp: Using echo y as an automated response to a pcp hostkey prompt

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
0

& "echo y | C:\Program Files\PuTTY\plink.exe" makes echo y | part of the path to the executable.

Change this:

& "echo y | C:\Program Files\PuTTY\plink.exe" -ssh -batch -i $PrivateKeyPath $username "exit" 2>&1

into this:

echo 'y' | & 'C:\Program Files\PuTTY\plink.exe' -ssh -batch -i $PrivateKeyPath $username "exit" 2>&1
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • Hi Ansgar, I do not receive my original error message but the server key is still not cached. – Alex_P Oct 16 '19 at 08:50