I'm trying to create a C# program using SSH.Net lib to change some config in a SSH enabled cisco router. But I'm getting "Permission denied" Error while trying to establish connection. But I'm able to access the router through putty/plink using the username and password.
using (var client = new SshClient(routerIPAddr, 22, routerUserName, routerPassword))
{
_logger.Write("SSH client created");
try
{
client.Connect();
if (client.IsConnected)
{
_logger.Write("Connected to the router.");
// Execute router commands
ExecuteRouterCommands(client, commands);
client.Disconnect();
_logger.Write("Disconnected from the router.");
}
else
{
_logger.Write("Failed to connect to the router.");
}
}
On executing i got this error
Permission denied (password). at Renci.SshNet.ClientAuthentication.Authenticate(IConnectionInfoInternal connectionInfo, ISession session)
at Renci.SshNet.ConnectionInfo.Authenticate(ISession session, IServiceFactory serviceFactory)
at Renci.SshNet.Session.Connect()
at Renci.SshNet.BaseClient.CreateAndConnectSession()
at Renci.SshNet.BaseClient.Connect()
I also tried keyboardInteractiveAuthenticationMethod
var authMethod = new KeyboardInteractiveAuthenticationMethod(routerUserName);
authMethod.AuthenticationPrompt += (sender, e) =>
{
e.Prompts.Single().Response = routerPassword;
};
var connectionInfo = new ConnectionInfo(routerIPAddr, 22, routerUserName, authMethod);
using (var client = new SshClient(connectionInfo))
//////////////
......
client.Connect();
......
same code
/////////////
On executing I got similar error again.
Permission denied (keyboard-interactive). at Renci.SshNet.ClientAuthentication.Authenticate(IConnectionInfoInternal connectionInfo, ISession session)
at Renci.SshNet.ConnectionInfo.Authenticate(ISession session, IServiceFactory serviceFactory)
at Renci.SshNet.Session.Connect()
at Renci.SshNet.BaseClient.CreateAndConnectSession()
at Renci.SshNet.BaseClient.Connect()
Is there anyway to fix this authentication issue.