在C#应用程序中使用Plink会话逃避SSH主机验证

时间:2019-09-05 10:51:29

标签: c# .net ssh putty plink

我正在创建的应用程序是C#,而我刚遇到PuTTY的SSH主机验证问题。

尝试运行Plink会话时。

当我已经运行了该特定主机时,我遇到了主机密钥缓存问题。

赞:

  

如果您只想进行一次连接,而无需   将密钥添加到缓存中,输入“ n”。   如果您不信任此主机,请按Return键放弃   连接。   将密钥存储在缓存中? (是/否)

我想自动写“是”的想法。

在完成一些互联网搜索之后,我找到了一种解决方案:

echo y | plink.exe <the rest of arguments>

但是我正在使用以下代码的问题:

var processStartInfo = new ProcessStartInfo()
    {
        CreateNoWindow = true,
        FileName = Path.Combine(@"plink.exe"),
        Arguments = string.Format(@"-L {0}:{1}:{2} {3}@{4} -pw ""{5}"" -N -v", {Local forwarding port}, "localhost", {Host port}, "root", ProxyIpAfterPicked, textBox2.Text),
        RedirectStandardError = true,
        RedirectStandardInput = true,
        RedirectStandardOutput = true,
        UseShellExecute = false
    };

我注意到有些人的例子通过了StreamWriter.Writeline("y"),但是它也不起作用。 有什么办法可以使用特定代码,只是在其中添加参数,或者是我一无所知。

1 个答案:

答案 0 :(得分:1)