C# 无法使用Rencish连接到Mac
我无法使用.NET应用程序中的Renci.SshNet库远程连接到Mac系统(OS X 10.10.5)。我使用的代码允许我连接到任何其他linux操作系统,如RHL、Ubuntu等。我可以通过putty连接到这个Mac系统。但是,当我尝试从.NET应用程序连接时,会出现以下错误- 未找到合适的身份验证方法来完成身份验证(公钥、键盘交互)。来源:Renci.SshNet 这是我的密码。请帮忙C# 无法使用Rencish连接到Mac,c#,macos,ssh,C#,Macos,Ssh,我无法使用.NET应用程序中的Renci.SshNet库远程连接到Mac系统(OS X 10.10.5)。我使用的代码允许我连接到任何其他linux操作系统,如RHL、Ubuntu等。我可以通过putty连接到这个Mac系统。但是,当我尝试从.NET应用程序连接时,会出现以下错误- 未找到合适的身份验证方法来完成身份验证(公钥、键盘交互)。来源:Renci.SshNet 这是我的密码。请帮忙 public SshClient sshClient; sshClient = new SshClien
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();
谢谢-这对我来说非常有效。我做了一个修改-以便可以向处理程序传递密码:
kauth.AuthenticationPrompt+=(sender,e)=>HandleKeyEvent(sender,e,password)代码>和签名更改:私有静态无效HandleKeyEvent(对象发送者,Renci.SshNet.Common.AuthenticationPromptEventArgs e,字符串密码)
谢谢!为我工作,改动很少(在新的库版本中没有端口参数,服务器发送单词“Password:”而不是“:”,就像这个“Password”)。
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;
}
}
}