Need help with ssh.net keyboard interactive authentication in PowerShell

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Deepak Verma Deepak Verma 3 months, 1 week ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #35841
    Profile photo of Deepak Verma
    Deepak Verma
    Participant

    Hi,

    I am writing a PowerShell script to connect to Linux servers and run few commands. To connect to Linux servers, I am using Renci SSH .NET library. Few Linux flavors do support direct login while some do not. Those Linux servers only support keyboard interactive logins. In case of keyboard interactive authentication, we need to wait for the Linux to prompt for password and we need to detect that in code and pass password.

    I have written code for direct login but need some help to write code for keyboard interactive authentication. I think we would need to use eventhandler.

    Below is the sample code of login to Linux server with direct authentication (without keyboard interactive authentication)

    ===================================sample code without keyboard interactive authentication==============================

    [void][reflection.assembly]::LoadFrom((Resolve-Path "c:\Deepak\Renci.SshNet.dll"))

    $SshClient = New-Object Renci.SshNet.SshClient("10.31.139.32", 22, "admin", "8RttoTriz")

    $SshClient.Connect()

    if ($SshClient.IsConnected) {

    $SshCommand = $SshClient.RunCommand("ifconfig")

    $ifconfig = $SshCommand.Result.Split("`n")

    }

    $SshCommand

    ===================================sample code without keyboard interactive authentication==============================

    Below is the error when I try to connect to a Linux server which only supports keyboard interactive authentication

    ===================================================error==========================================================

    PS C:\Deepak> .\testssh.ps1

    Exception calling "Connect" with "0" argument(s): "No suitable authentication method found to complete authentication

    (publickey,keyboard-interactive)."

    At C:\Deepak\testssh.ps1:5 char:1

    + $SshClient.Connect()

    + ~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : SshAuthenticationException

    ===================================================error==========================================================

    Sample of a keyboard interactive login written in C#

    http://stackoverflow.com/questions/15686276/unable-to-connect-to-aixunix-box-with-ssh-net-library-error-value-cannot-b

    https://www.nsoftware.com/kb/xml/09170801.rst

    You can download Renci SSH .Net library from below link

    https://sshnet.codeplex.com/downloads/get/944155

    Regards,

    Deepak

    #35909
    Profile photo of Max Kozlov
    Max Kozlov
    Participant
    #44555
    Profile photo of Deepak Verma
    Deepak Verma
    Participant

    cant use a module for few reasons,

    Please help

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.