简体   繁体   English

如何将“y”传递给使用 PowerShell Start-Process 启动的 pscp 进程?

[英]How to pass "y" to pscp process started with PowerShell Start-Process?

I would like to pscp some files from Windows to Linux server.我想将一些文件从 Windows pscp到 Linux 服务器。 The following code (PowerShell) is what I was trying.以下代码(PowerShell)是我正在尝试的。 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.它工作正常,但我需要输入y ,当它尝试与远程服务器通信时,因为 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?服务器的 ssh 密钥指纹为:xxxxxx 如果信任此主机,输入“y”将密钥添加到 PuTTY 的缓存中并继续连接……将密钥存储在缓存中? (y/n) (是/否)

Is there any way to echo "y" automatically (non-interactive) while using Start-Process ?有没有办法在使用Start-Process时自动echo "y" (非交互式)? Or disable Windows's SSH host checking (even better for me)?或者禁用 Windows 的 SSH 主机检查(对我来说更好)?

Any helps are appreciated.任何帮助表示赞赏。

Do not try to blindly answer "y" to pscp host key verification prompt.不要试图在pscp主机密钥验证提示中盲目回答“y”。 You lose a protection against man-in-the-middle attacks .您失去了针对中间人攻击的保护

You should use the -hostkey switch with your host key fingerprint.您应该将-hostkey开关与您的主机密钥指纹一起使用。


A host key is part of the information you should have about any SSH server, along with the credentials.主机密钥是您应该拥有的有关任何 SSH 服务器以及凭据的信息的一部分。 – Though as a compromise, you may want to implement an equivalent of OpenSSH accept-new mode. – 尽管作为折衷方案,您可能希望实现等效的 OpenSSH accept-new模式。 For an example, see WinSCP article Implementing SSH host key cache (known hosts) .有关示例,请参阅 WinSCP 文章实现 SSH 主机密钥缓存(已知主机) – If you use "MD5" instead of "SHA-256" , you will get the fingerprint almost in the format needed for pscp . – 如果您使用"MD5"而不是"SHA-256" ,您将获得几乎pscp所需格式的指纹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM