Simple Connection Exception issue (I hope)

Mar 10, 2012 at 3:03 PM

Hi everyone,

I am relatively new to using SSH in any maner.  But I have recently been using the Tamir SSH stuff and it was easy enough.  But it lacked some features I was looking for.  Then I got turned on to this library and by looking at some of the code samples look like more of what I want/need.   Anyway I have been using the before mentioned library just fine with a supplied host/dns , user and password combination and no private/public keys.  Also when using putty or filezilla i only supply password and user name.

So I am wondering if I missed something when I tried to use this library.   I do this in code

PasswordConnectionInfo

 p

assinfo = new PasswordConnectionInfo host, user, password); new SftpClient(passinfo);

and then I get the following error:

An unhandled exception of type 'Renci.SshNet.Common.SshAuthenticationException' occurred in Renci.SshNet.dll

Additional information: No suitable authentication method found to complete authentication.



Can anyone please help me understand what I have done wrong or am missing?



Thanks

Darryl

 sftpClient =

 sftpClient.connect();

Coordinator
Mar 10, 2012 at 3:10 PM

Hi,

 

Well, in theory this error can occur when you trying to connect to ssh server using authentication method that it does not support.

For example, if SSH supports only keyboard interactive but you using password you will get this exception.

Or when it support private key and host and you using password, again, will get the same exception.

 

What server you trying to connect to?

Do you manage to connect to there using putty? if so I bet you provide username/password combination.

In some cases I saw that this method is confused with keyboard-interactive and putty make it seamless even so its different method.

 

I would suggest to try different authentication methods and see if they work, especially KeyboardInteractive one.

 

Hope it helps.

 

Thanks,

Oleg

Mar 10, 2012 at 3:15 PM

Hi,

 

Thanks for the advice.  I have checked with file zilla and I made sure it says "normal" and not " interactive" or "ask for password".  I didn't see where I had the option in putty to check.   But filezilla logs in fine with pass/user.   I've never had to supply a key?   Sorry if this sounds ignorant, I am very new to ssh and trying to wrap my head around it.   Thanks for all your efforts though the library looks amazing.  I can't wait to get past this issue and try it out.

Thanks

Darryl

Mar 10, 2012 at 3:25 PM

Sorry more clairification.  I checked putty yes it's in keyboard interactive mode.   However, filezilla does not.    I also did not have to do keyboard interactive mode when I was using the previous ssh by tamir.   I did try keyboard interactive mode in this library(which in the long run won't be suitable for me) and now i'm getting an null error.  :)

Fun fun

Mar 10, 2012 at 5:56 PM

Hi Oleg,

 

You were absolutely right.  I chased through the Tamir ssh library and underneath they were creating a keyboardinteractive class, however, it allowed me to supply a password and it did all the authentication for me.   I look at creating a keyboard interactive class with the ssh.net and I didn't see where it allowed me to supply a password.  Is there something I missed?  Or is this functionality not present?

 

Thanks in advance

Darryl

Coordinator
Mar 10, 2012 at 6:16 PM

Hey,
Currently not home so cant provide you with example but i would search this forum, i am sure there is an rxample somewhere.

If you cannt find it let me know and i will post it when i have a chance.

Thanks,
Oleg

On Mar 10, 2012 12:56 PM, "DarrylIngalls" <notifications@codeplex.com> wrote:

From: DarrylIngalls

Hi Oleg,

You were absolutely right. I chased through the Tamir ssh library and underneath they were creating a keyboardinteractive class, however, it allowed me to supply a password and it did all the authentication for me. I look at creating a keyboard interactive class with the ssh.net and I didn't see where it allowed me to supply a password. Is there something I missed? Or is this functionality not present?

Thanks in advance

Darryl

Read the full discussion online.

To add a post to this discussion, reply to this email (sshnet@discussions.codeplex.com)

To start a new discussion for this project, email sshnet@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Mar 15, 2012 at 5:44 PM
Edited Mar 15, 2012 at 8:24 PM

Hey Darry,

Did you get any further with this?. I'm just about to have a look for this one my self has I am trying to connect to two similar but different devices, one works fine by supplying User and Password via ConnectionInfo, the other doesn't as it asks for Keyboard Interactive Login.

The problem I will be faced with is that I may not know the type of the device I will be connected to prior to connecting to it so I need a method that will work on both.

Each device provide the user with a different prompt when using Putty e.g.

Device 1 : user@hosts's password:
(PasswordConnectionInfo works OK here)

Device 2 : "Password: "
(KeyboardInteractiveConnectionInfoworks OK here)

Mar 15, 2012 at 6:19 PM

There might be an answer here which also includes a VB example (need to import Renci.SshNet.Common). C# is way out of my league - in fact VB is a struggle.

Mar 15, 2012 at 8:22 PM

Well I got the Keyboard Interactive Login to function, but now (of course) I can't log into the original device using PasswordConnectionInfo

Is there anyway to automate the login process no matter how it occurs at the server so that the user become obvious to the type of login required?

i.e. If the user supplies a password user name combo, then can SSH Client determine the login type and login normally (using PasswordConnectionInfo) by simply passing this info as part of ConnectionInfo(host, User, Pass) or interactively (using KeyboardInteractiveConnectionInfo) using the AddHandler for ConnectionInfo.AuthenticationPrompt?

Coordinator
Mar 15, 2012 at 9:31 PM

Hi,

 

I recently implemented multiple authentication methods support so see if it works for you.

One of the side effects what it will do is will pick up one of the supported authentication methods by the server so I think it should do the trick.

Here is a code example with private key :

var connectionInfo = new ConnectionInfo("server", 22, "username",
                    new PasswordAuthenticationMethod("username", "password"),
                    new PrivateKeyAuthenticationMethod("username",
                         new PrivateKeyFile(File.OpenRead(@"rsa_pass_key.txt"), "tester"),
                         new PrivateKeyFile(File.OpenRead(@"dsa_pass_key.txt"), "tester")
                         )
                );

Hope it helps.

 

Thanks,

Oleg

Mar 15, 2012 at 11:14 PM

Cheers Oleg,

Can I ask what build version you implemented this in? I currently have your build 14770 (from only a week ago or so) but when I add New KeyboardInteractiveConnectionInfo(Host, User) as a Authentication parameter in the NEW method of ConnectionInfo, but the overload fails.

Mar 15, 2012 at 11:40 PM

Just shoot me now! Maybe if I added another AuthenticationMethod rather than another ConectionInfo object I'dd get somewhere. Sorry for wasting people reading time. Argghhh. One of these days I really need to understand programming at a deeper level that just form buttons.

Mar 16, 2012 at 12:21 AM

Hmm, still can't quite get it. Now have a New ConnectionInfo object with the Password and KeyboardInteractive authentication methods such that:

 

        Dim ConnectionInfo = New ConnectionInfo(Host, 22, User,
                            New PasswordAuthenticationMethod(User, Pass),
                            New KeyboardInteractiveAuthenticationMethod(User))

but when specifying a KeyboardInteractiveConnectionInfo directly (instead of the base class) you can add and event handler for the AuthenticationPrompt event (as show in Oleg example in this post), but now this event is not available in the base ConnectionInfo class. Running the above as is results in and exception "Value cannot be null, Parameter name: data"

 

Coordinator
Mar 16, 2012 at 12:57 AM

Hi,

What happens now is all those events are still available but they are in KeyboardInteractiveAuthenticationMethod class.

So you will need to create instance of this class before that and attach any events that you need to handle.

 

Let me know if you have any problems.

 

Thanks,

Oleg

KeyboardInteractiveAuthenticationMethod
Mar 16, 2012 at 1:33 AM

Holly crap, I actually understood that, did it and it worked!

        Dim PasswordConnection = New PasswordAuthenticationMethod(User, Pass)
        Dim KeyboardInteractive = New KeyboardInteractiveAuthenticationMethod(User)
        Dim ConnectionInfo = New ConnectionInfo(Host, 22, User, PasswordConnection, KeyboardInteractive)

        AddHandler KeyboardInteractive.AuthenticationPrompt, _
                    Sub(sender As Object, e As AuthenticationPromptEventArgs)
                        For Each prompt In e.Prompts
                            Debug.Print(prompt.Request)
                            If Not prompt.Request.IndexOf("Password:", StringComparison.InvariantCultureIgnoreCase) = -1 Then
                                prompt.Response = Pass
                            End If
                        Next
                    End Sub

I did try to separate the even handler subroutine out from the main procedure but I needed to pass in another parameter (Pass). Although this is straight forward when calling normal procedures, I couldn't figure this out for the Event handler - but this is for another day.

Many thanks for the prompts.

Apr 4, 2012 at 12:58 PM
How would one write this in Powershell?
I can't seem to get my head around the AddHandler portion of the above code.
Coordinator
Apr 4, 2012 at 3:01 PM

Hi,

 

Sorry, I am not an expert in Powershell.

May be somebody else can reply to that.

 

Thanks,

Oleg

Jul 25, 2012 at 6:07 AM

In PowerShell this would be the equivalent, but I can't get it to work there. I'm getting the exception mentioned earlier by swinster: "Value cannot be null, Parameter name: data" but I can't figure out where that's coming from, the stack trace is:

   at Renci.SshNet.KeyboardInteractiveAuthenticationMethod.Authenticate(Session session)
   at Renci.SshNet.ConnectionInfo.Authenticate(Session session)
   at Renci.SshNet.Session.Connect()
   at Renci.SshNet.BaseClient.Connect()
   at CallSite.Target(Closure , CallSite , Object )

Even after looking at source code, I can't figure out what "data" parameter is null. I'll have to grab all the source and hook up a debugger. Anyway, this is what I think should work (and if you run it, can see it prompts you and everything seems to be working right up to the exception):

function Get-SharpSsh {
param($Server =  'entertainer', $Username = 'user', $Password = 'password')
    Add-Type -path ".\Renci.SshNet.dll"

    # $PasswordConnection = New-Object Renci.SshNet.PasswordAuthenticationMethod $Username, $Password
    $KeyboardInteractive = New-Object Renci.SshNet.KeyboardInteractiveAuthenticationMethod $Username

    Register-ObjectEvent $KeyboardInteractive AuthenticationPrompt -Action {
        param($Sender, $AuthenticationPromptEventArgs)
        # Write-Host $( $Sender | Out-String ) -Fore Green
        # Write-Host $( $AuthenticationPromptEventArgs | Out-String ) -ForegroundColor Cyan
    
        foreach( $Prompt in $AuthenticationPromptEventArgs.Prompts ) {
            $Prompt.Response = Read-Host $Prompt.Request.Trim(": ")
        }
        Write-Host $( $event.SourceEventArgs.Prompts | Out-String ) -ForegroundColor Green
    } | Out-Null

    $ConnectionInfo = New-Object Renci.SshNet.ConnectionInfo $Server, 22, $Username, $KeyboardInteractive

    $SshClient = New-Object Renci.SshNet.SshClient $ConnectionInfo
    $SshClient.Connect()
    ### This should return a connected client
    return $SshClient
    # $SshClient.RunCommand('uname -a').Result
    # $SshClient.Disconnect()
    # $SshClient.Dispose()
    # $SshClient = $null
}

 

By the way, you could hypothetically replace

Register-ObjectEvent $KeyboardInteractive AuthenticationPrompt -Action { ... }

With

$KeyboardInteractive.add_AuthenticationPrompt({ ... })

But if you try that, you'll see you get a "There is no Runspace available to run scripts in this thread." PSInvalidOperationException, which means ssh library is doing threading and the event is being throw on some thread other than the default PowerShell thread. I assume that what's going on is probably a result of that, but I can't see why right away.

Oct 15, 2012 at 12:52 AM

Where you ever able to figure it out in PowerShell?

Oct 15, 2012 at 4:20 AM

I don't know about anyone else, but I gave up, honestly -- I didn't care enough to get source and hook up a debugger, and couldn't figure anything out without doing so.