本文介绍了Renci.sshnet:在Vb.net中找不到合适的身份验证方法来完成身份验证(公钥,键盘交互)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试连接到Linux Suse服务器时出现错误:找不到合适的身份验证方法来完成身份验证(公钥,键盘交互).我可以使用端口22上的腻子连接到同一台服务器.
When trying to connect to Linux Suse server getting error : No suitable authentication method found to complete authentication (publickey,keyboard-interactive). I'm able to connect to same server using putty on port 22.
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)
推荐答案
尝试以下代码:
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
这篇关于Renci.sshnet:在Vb.net中找不到合适的身份验证方法来完成身份验证(公钥,键盘交互)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!