我正在使用 c# 中的 plink 连接到 Linux 服务器并运行一些程序。c# 控制台程序和 plink.exe 都在同一台 windows 机器上。
问题是当我第一次连接到 Linux 服务器时,plink 会询问我是否要接受并存储来自 Linux 服务器的 SSH 密钥。我总是想对此做出回应,因为所有服务器都在我的局域网中,并且没有安全问题。
我正在使用 c# Process 类型,将正确的参数传递给 plink,重定向输出并启动。现在问题是当plink提示时,process.StandardOutput.ReadToEnd(); 挂起,我无法弄清楚 plink 是否提示我接受密钥或实际登录到 Linux 服务器。
string output = string.Empty;
string error = string.Empty;
string arguments = @" -ssh -pw password root@12.12.12.12 ./Install_xxx.bin";
using (Process process = new Process())
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "plink";
psi.Arguments = arguments;
psi.ErrorDialog = false;
psi.UseShellExecute = false;
psi.RedirectStandardError = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;
psi.CreateNoWindow = true;
process.StartInfo = psi;
process.Start();
output = process.StandardOutput.ReadToEnd();
error = process.StandardError.ReadToEnd();
}
谢谢