无法使用RenciSSH连接到Mac
本文关键字:连接 Mac RenciSSH | 更新日期: 2023-09-27 18:03:33
我无法使用Renci远程连接到Mac系统(OS X 10.10.5)。. net应用程序中的SshNet库。我使用的代码允许我连接到任何其他linux操作系统,如RHL, Ubuntu等。我可以通过putty连接到这个Mac系统。但是当我尝试从我的。net应用程序连接时,它给了我以下错误-
没有找到合适的身份验证方法来完成身份验证(publickey,keyboard-interactive)。来源-仁慈。SshNet
这是我的代码。请帮助
public SshClient sshClient;
sshClient = new SshClient(ipAddress, port, username, password);
sshClient.KeepAliveInterval = TimeSpan.FromSeconds(60);
sshClient.Connect();
基于stackoverflow上的各种贡献,认为mac要求键盘身份验证,而我的方法只有基于密码的身份验证。所以这段更新后的代码同时做....感谢所有的贡献者…
public SshClient sshClient;
KeyboardInteractiveAuthenticationMethod kauth = new KeyboardInteractiveAuthenticationMethod(username);
PasswordAuthenticationMethod pauth = new PasswordAuthenticationMethod(username, password);
kauth.AuthenticationPrompt += new EventHandler<Renci.SshNet.Common.AuthenticationPromptEventArgs>(HandleKeyEvent);
ConnectionInfo connectionInfo = new ConnectionInfo(ipAddress, port, username, pauth, kauth);
sshClient = new SshClient(connectionInfo);
sshClient.KeepAliveInterval = TimeSpan.FromSeconds(60);
sshClient.Connect();
和密码提示事件
的事件处理程序代码 void HandleKeyEvent(Object sender, Renci.SshNet.Common.AuthenticationPromptEventArgs e)
{
foreach (Renci.SshNet.Common.AuthenticationPrompt prompt in e.Prompts)
{
if (prompt.Request.IndexOf("Password:", StringComparison.InvariantCultureIgnoreCase) != -1)
{
prompt.Response = password;
}
}
}