I would like to pscp
some files from Windows to Linux server. The following code (PowerShell) is what I was trying. It worked fine, but I need to input y, when it's trying to communicate with remote server, cause the hostname is unknown for Windows.
$proc = Start-Process powershell.exe -Credential $credential -ArgumentList "Start-Process C:\pscp.exe -Verb RunAs -ArgumentList '-i C:\prikey.ppk D:\temp\* corey@11.22.33.44:/home/corey/' -Wait" -PassThru
$proc.WaitForExit()
It will show something like 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 ssh key fingerprint is: xxxxxx If you trust this host, enter "y" to add the key to PuTTY's cache and carry on connecting...... Store key in cache? (y/n)
Is there any way to echo "y"
automatically (non-interactive) while using Start-Process
? Or disable Windows's SSH host checking (even better for me)?
Any helps are appreciated.
Do not try to blindly answer "y" to pscp
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.
A host key is part of the information you should have about any SSH server, along with the credentials. – Though as a compromise, you may want to implement an equivalent of OpenSSH accept-new
mode. For an example, see WinSCP article Implementing SSH host key cache (known hosts). – If you use "MD5"
instead of "SHA-256"
, you will get the fingerprint almost in the format needed for pscp
.