gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 14:28:29 24 4
gpt4 key购买 nike

我想pscp一些文件从 Windows 到 Linux 服务器。以下代码(PowerShell)是我正在尝试的。它工作正常,但我需要输入 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()

它将显示如下内容:

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)



有没有办法 echo "y"使用 Start-Process 时自动(非交互) ?或者禁用 Windows 的 SSH 主机检查(对我来说更好)?

任何帮助表示赞赏。

最佳答案

不要试图对 pscp 盲目地回答“y”。主机 key 验证提示。您失去了对 man-in-the-middle attacks 的保护.

您应该使用 -hostkey switch使用您的主机 key 指纹。

主机 key 是您应该拥有的有关任何 SSH 服务器的信息的一部分,以及凭据。 – 尽管作为一种折衷方案,您可能希望实现等效的 OpenSSH accept-new模式。有关示例,请参阅 WinSCP 文章 Implementing SSH host key cache (known hosts) . – 如果您使用 "MD5"而不是 "SHA-256" ,您将获得几乎为 pscp 所需格式的指纹。 .

关于powershell - 如何将 "y"传递给使用 PowerShell Start-Process 启动的 pscp 进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59485831/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com