简体   繁体   中英

C# Renci.SshNet.Common.SshAuthenticationException: 'Permission denied (password).'

Its so strange and wired to me. The working code all of a sudden throwing exception without even changing anything in code. Please help me to understand why I am getting this kind of error? Why my working code is broken without changing anything. Username, Password and IP address used are correct. I can connect to same IP with same password using putty or any other 3rd party tool but same is not working when I try to connect from my C# code.

           SshClient _client = new SshClient(ipaddress, username, password);
            _client.Connect();
            labelControl5.Text = "Connection: " + _client.IsConnected;
            if (_client.IsConnected)
            {
                stream = _client.CreateShellStream("sys rst", 80, 24, 800, 600, 1024);
                StringBuilder answer = sendCommand("sys rst");
                MessageBox.Show(answer.ToString());
            }
            else
            {
                MessageBox.Show("Connection failed " + _client.IsConnected);
            }

Error Message: 在此处输入图像描述

I am new to this C# world and being stuck on this issue to figuring it out from last 2 weeks. Pls pls help.

This is how I am using the authentication in calls using Renci.. perhaps the AuthenticationMethod would help you get going.

List<AuthenticationMethod> authMethods = new List<AuthenticationMethod>();
authMethods.Add(new PasswordAuthenticationMethod(username, password));

ConnectionInfo sshConnectionInfo = new ConnectionInfo(ipaddress, 22, username, authMethods.ToArray());

var sshClient = new SshClient(sshConnectionInfo);
sshClient.Connect();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM