Connecting to OpenSSH server

Apr 3, 2013 at 10:53 AM
I have set up an OpenSSH server and try to connect using the following code:
var connectionInfo = new ConnectionInfo(host, 22, username, new PasswordAuthenticationMethod(username, password));
            //var connectionInfo = new ConnectionInfo(host, 22, username, new KeyboardInteractiveAuthenticationMethod(username));
            try
            {
                using (var client = new ScpClient(connectionInfo))
                {
                    client.HostKeyReceived += delegate(object sndr, HostKeyEventArgs ex)
                    {
                        if (ex.FingerPrint.SequenceEqual(new byte[] { 0x2a, 0x08, 0xd5, 0x69, 0xe0, 0x9f, 0xcc, 0xdb, 0x3d, 0xc2, 0x78, 0x06, 0x61, 0xd0, 0xf4, 0xc4 }))
                        {
                            ex.CanTrust = true;
                        }
                        else
                        {
                            ex.CanTrust = false;
                        }
                    };
                    client.Connect();
                    //  Do something here
                    client.Disconnect();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
but I get a "User cannot be authenticated exception. I can login fine with Putty and WinSCP. What could be the problem?

(I'm no SSH expert, or even a novice)
Coordinator
Apr 3, 2013 at 2:42 PM
Hi,

I would suggest try different authentication method like KeyboardInteractive since sometimes putty will use this method even so it looks like it uses username/password combination.

Also, please download latest source code version since recently I fixed a bug, reported by other user, which had to do with user not authenticated which might fix your problem.

Hope it helps,
Thanks,
Oleg
Apr 6, 2013 at 8:54 AM
It is working now. I don't see the difference so maybe it was something else I was doing wrong...
        public Boolean VerifyConnetion()
        {
            var passwordAuthMethod = new PasswordAuthenticationMethod(username, password);
            var connectionInfo = new ConnectionInfo(host, port, username, passwordAuthMethod);

            try
            {
                client = new ScpClient(connectionInfo);
                client.HostKeyReceived += HandleHostKeyReceived; ;
                client.Connect();
                client.Disconnect();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
        }

        private void HandleHostKeyReceived(object sender, HostKeyEventArgs ex)
        {
            if (ex.FingerPrint.SequenceEqual(new byte[] { 0x2a, 0x08, 0xd5, 0x69, 0xe0, 0x9f, 0xcc, 0xdb, 0x3d, 0xc2, 0x78, 0x06, 0x61, 0xd0, 0xf4, 0xc4 })) // TODO
            {
                ex.CanTrust = true;
            }
            else
            {
                ex.CanTrust = false;
            }
        }