Renci.sshnet:在Vb.net中找不到合适的身份验证方法(公钥,键盘交互)

时间:2017-06-10 21:35:06

标签: authentication

尝试连接到Linux Suse服务器时出现错误:找不到合适的身份验证方法(公钥,键盘交互式)。我可以使用端口22上的putty连接到同一台服务器。

        Dim strLogs As String
        Dim Struser As String = "er_xxxx"
        Dim Strpass As String = "xxxx"
        Dim cmd as SshCommand 
        Dim sshConnectionInfo = New PasswordConnectionInfo("169.144.xx.xxx", Struser, Strpass)
        Dim ssh As New Renci.SshNet.SshClient(sshConnectionInfo)

        ssh.Connect()

        cmd = ssh.RunCommand("whoami")

        strLogs = cmd.Result

        ssh.Disconnect()

        Response.Write(strLogs)

1 个答案:

答案 0 :(得分:0)

尝试以下代码:

Private Sub HandleKeyEvent(sender As Object, e As Renci.SshNet.Common.AuthenticationPromptEventArgs)
    For Each prompt As Renci.SshNet.Common.AuthenticationPrompt In e.Prompts
        If prompt.Request.IndexOf("Password:", StringComparison.InvariantCultureIgnoreCase) <> -1 Then
            prompt.Response = "Password"
        End If
     Next
 End Sub

 Public Function SSH_Connection_Test(ByVal UserName As String, ByVal HostName As String, ByVal Password As String) As String

     Dim Result As String = Nothing

     Dim kauth = New KeyboardInteractiveAuthenticationMethod(UserName)
     AddHandler kauth.AuthenticationPrompt, AddressOf HandleKeyEvent
     Dim pauth = New PasswordAuthenticationMethod(UserName, Password)

     Dim connInfo As New Renci.SshNet.ConnectionInfo(HostName, UserName, kauth, pauth)

     Dim sshClient As New Renci.SshNet.SshClient(connInfo)

     Dim cmd As Renci.SshNet.SshCommand

     Using sshClient

         sshClient.Connect()

         cmd = sshClient.RunCommand("ls -a")

         Result = cmd.Result

         sshClient.Disconnect()
     End Using

     Return Result

 End Function