我无法使用.NET应用程序中的Renci.SshNet库远程连接到Mac系统(OS X 10.10.5).我使用的代码使我可以连接到任何其他linux操作系统,例如RHL,Ubuntu等.我可以通过腻子连接到该Mac系统.但是,当我尝试从.NET应用程序连接时,出现以下错误-
No suitable authentication method found to complete authentication (publickey,keyboard-interactive). Source – Renci.SshNet
这是我的代码.请帮忙
<code>public SshClient sshClient; sshClient = new SshClient(ipAddress, port, username, password); sshClient.KeepAliveInterval = TimeSpan.FromSeconds(60); sshClient.Connect(); </code>
解决方法:
基于对stackoverflow的各种贡献,发现mac正在要求键盘认证,而我的方法仅具有基于密码的认证.因此,此更新的代码可同时实现这两种功能….感谢所有贡献者…
<code> 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();
</code>
以及密码提示事件的此事件处理程序代码
<code> 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;
}
}
}
</code>
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!