SSH connection issue

Jun 28, 2012 at 5:55 PM

Hi ,

I am new to SSH concepts. I am trying to use this library to create an SSH connection but i get an error "invalida authentication).

Can someone please tell me what i am doing wrong. This is in C#.

Here is the code i use :

using (Renci.SshNet.SftpClient sftp = new Renci.SshNet.SftpClient("192.168.100.100",22, "root", "root"

))

 

MessageBox .Show(sftp.IsConnected.ToString());  

}

{

sftp.Connect(); 

 

Coordinator
Jun 28, 2012 at 6:41 PM

I dont think you can connect as root user, other then that, everything else looks valid so it should work.

Try different user.

 

Thanks,

Oleg

Jun 28, 2012 at 8:09 PM

Hi Oleg,

 

Created another user and I tried the same with the new user.  I am getting the same error "No Suitable authentication method found to complete authentication.

System.Collections.ListDictionaryinternal"

What do you think is the issue. I am able to connect Putty and WinSCP. First time connection with Putty asks for the rsa key to be cached. Could this be something to do with the rsa key?

I am connecting to Suse Linux.

Thanks.

Jun 29, 2012 at 10:33 PM

Hi Oleg,

 

Can you please suggest a resolution for the issue.

Jul 9, 2012 at 8:54 PM

Would appreciate any reply on this.

 

Thanks in advance.

Coordinator
Jul 9, 2012 at 9:19 PM

Hi,

 

Sorry for delay in reply, simply very busy with other project.

 

I suspect server expect keyboard authentication, which putty does by default.

 

try this:

            var connectionInfo = new KeyboardInteractiveConnectionInfo(host, port, username);

            connectionInfo.AuthenticationPrompt += delegate(object sender, AuthenticationPromptEventArgs e)
            {
                foreach (var prompt in e.Prompts)
                {
                    if (prompt.Request.Equals("Password: ", StringComparison.InvariantCultureIgnoreCase))
                    {
                        prompt.Response = password;
                    }
                }
            };

            using (var ssh = new SshClient(connectionInfo))
            {
                ssh.Connect();
                var cmd = ssh.RunCommand("who");
                return cmd.Result;
            }

Hope it helps.

 

Thanks,

Oleg

Jul 9, 2012 at 9:46 PM

Thanks Oleg.

Can you tell me which namespace has the "AuthenticationPromptEventArgs". I am using C# .Net 4.x

 

Jul 9, 2012 at 10:52 PM

Got it. It was in Renci.SshNet.Common

The program works now. Thanks Oleg.


Coordinator
Jul 10, 2012 at 8:07 PM

No problem, sorry for late responses, I have a deadline on another project which I must finish so dont really have much time lately for this one :(

 

Thanks,

Oleg

Jul 18, 2012 at 12:22 AM

Hi Oleg,

 

I am trying to connect to a server running SUSE Linux using the following code :

[c# .Net3.5 code]

serverConnection = new SshClient(serverName, userName, password);

serverConnection.Connect();

I am getting the following error message :

 

"No suitable authentication method found to complete authentication. at Renci.SshNet.ConnectionInfo.Authenticate(Session session) at Renci.SshNet.Session.Connect() at Renci.SshNet.BaseClient.Connect()"

When I change the connection method to "KeyboardInteractiveConnectionInfo", per your suggestion I am able to connect to the SUSE Linux server successfully. But this connection method does not work in case of server running Windows or RHEL. 

Please note that "SsshClient" method works well for servers running Windows2k8-R2 and RHEL (that is all I have tested so far).

 

My problem is that I have a collection of Windows2k8-R2,Windows2k3, RHEL, SUSE etc servers that I need to talk to. While the user enters the server name, I need to SSH to the server and collect some information. I wouldn't know the OS type when the user inputs the server name or IP. So it would be better if I can have one connection method that I can use for all types of servers.

Do you have any suggestions? 

Hi Girishivarathri,

Were you able to connect to a server running  RHEL or Windows using "KeyboardInteractiveConnectionInfo" ?

 

Thanks,

Subbu

Coordinator
Jul 21, 2012 at 12:16 AM

Hi,

 

In one of the latest releases I added support for multiple connection methods.

 

Please get latest versions and check ConnectionInfo constructor. This is where you can provide multiple connection methods.

 

Hope it helps.

 

Thanks,

Oleg

Jul 23, 2012 at 11:36 PM

Hi Oleg,

 

Thanks for your response.

I downloaded the source code from the link "http://sshnet.codeplex.com/SourceControl/changeset/view/17229#". I believe that is the latest version as I dont see any other build available in the link "http://sshnet.codeplex.com/SourceControl/list/changesets?size=50". Please correct me if I am wrong. 

 

When I try to create a "dll" using the following steps:

- Right Click on the project Renci.SshNet.Net35

- Click on Properties and select the output type as "Class Library"

- Run the project.

I got an error message saying there were build errors. I noticed error messages like :

"Error 1 No overload for method 'RequestFStat' takes '1' arguments C:\Users\ssethuraman\Desktop\Docs\DB Project\Scripts\Renci.SshClient\Renci.SshNet\Sftp\SftpFileStream.cs 110 40 Renci.SshNet.NET35"

"Error 2 No overload for method 'RequestOpen' takes '2' arguments C:\Users\ssethuraman\Desktop\Docs\DB Project\Scripts\Renci.SshClient\Renci.SshNet\Sftp\SftpFileStream.cs 294 32 Renci.SshNet.NET35"

Can you please tell me if I am missing anything here. I dont have any experience creating "dll"s and it would be very helpful if you can guide me generate the dll.

Thanks in advance for your time!

Thanks,

Subbu

Jul 27, 2012 at 11:17 PM

Hi Oleg,

 

I got this issue resolved. Thanks.

I used the following code:

 

 var keyboardAuthMethod = new KeyboardInteractiveAuthenticationMethod(userName);               

keyboardAuthMethod.AuthenticationPrompt += delegate(Object senderObject, AuthenticationPromptEventArgs eventArgs)               

{    foreach (var prompt in eventArgs.Prompts) 

                  {                       

if (prompt.Request.Equals("Password: ", StringComparison.InvariantCultureIgnoreCase))                       

{                            prompt.Response = password;                   

        }                 

  }             

  };             

  var passwordAuthMethod = new PasswordAuthenticationMethod(userName, password);

   var connectInfo = new ConnectionInfo(serverName, userName, passwordAuthMethod, keyboardAuthMethod);

   serverConnection = new SshClient(connectInfo);               

 

Thanks,

Subbu

Jul 31, 2012 at 12:18 PM

 

Thanks, Subbu for posting that code.  I was having a similar problem connecting to an AIX system.  This was exactly what I needed.

 

And thank you, Oleg, for making this available!

 

Aug 13, 2012 at 8:25 PM

For me this worked:

var KeyboardInteractive = new KeyboardInteractiveAuthenticationMethod(username);

KeyboardInteractive.AuthenticationPrompt += delegate(Object senderObject, AuthenticationPromptEventArgs eventArgs) {

foreach (var prompt in eventArgs.Prompts) {

prompt.Response = password;

}

};

var connectionInfo = new ConnectionInfo(server, port, username, KeyboardInteractive); 

Dec 24, 2013 at 3:15 AM
Gives error: Value cannot be null. Parameter name: data
Jan 8 at 7:54 PM
Hello

Im a c# newbie, i used the code mentioned above with some modifications.

im trying to SSH into a linux busybox (unify Acces point)
the idea is to do a scheduled restart of the device, once every 24 hours.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Renci.SshNet;
using Renci.SshNet.Common;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            string host = "10.150.110.64",
                   username = "admin",
                   password = "pass";
            int    port = 22;

            var connectionInfo = new KeyboardInteractiveConnectionInfo(host, port, username);
            connectionInfo.AuthenticationPrompt += delegate(object sender, AuthenticationPromptEventArgs e)
            {
                foreach (var prompt in e.Prompts)
                {
                    if (prompt.Request.Equals("Password: ",StringComparison.InvariantCultureIgnoreCase))
                    {
                        prompt.Response = password;
                    }
                }



            };

            using (var ssh = new SshClient(connectionInfo))
            {

                ssh.Connect();
                ssh.RunCommand("reboot");
                ssh.RunCommand("exit");

            }

        }
    }
}
when i try to run it. it returns with SshAuthenticationException was unhandled
my thought is that this ssh connection needs to accept the algorithm key when connection to a server first time.

is there any way to do this? or am i all wrong in my assumption?

enlighten me oh great masters ;)

Best Regards
mrjinx