Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法使用Rencish连接到Mac_C#_Macos_Ssh - Fatal编程技术网

C# 无法使用Rencish连接到Mac

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

我无法使用.NET应用程序中的Renci.SshNet库远程连接到Mac系统(OS X 10.10.5)。我使用的代码允许我连接到任何其他linux操作系统,如RHL、Ubuntu等。我可以通过putty连接到这个Mac系统。但是,当我尝试从.NET应用程序连接时,会出现以下错误-

未找到合适的身份验证方法来完成身份验证(公钥、键盘交互)。来源:Renci.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();

谢谢-这对我来说非常有效。我做了一个修改-以便可以向处理程序传递密码:
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;
            }
        }
    }