Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Hello Stack Overflowers!

My goal is to utilize Powershell and SSH to connect to a Unix system (specifically an Avaya PBX switch). Once logged in, to change the terminal type to ossi (avaya specific) and issue a series of commands back and forth to collect data into a PowerShell object that I can work with. I currently have working profiles in Putty and Plink to do this at the command line with human interaction.

I have been beating my head against a wall for over a week trying to implement this script.

I have found (and tried) tons of different code pieces from around the web and some almost get it but none truly function right for my situation. I have been able to pin down that one of my problems is that to connect to the specific Unix system I am trying to get to, I have to use an authentication method known as "keyboard interactive". And while many open source ssh libraries/code snippets seem to support other forms of authentication, they skip this one.

Many folks recommend NetCmdlets (Link1), which I tried but this seems to not be set up to allow for back and forth conversations in SSH, nor does it appear to support Keyboard Interactive authentication.

The closest I have gotten things to working was utilizing a set of powershell SSH functions created by Joel Bennett and TaoK against a "custom" SharpSSH dll. PS for those reading this and trying to do something similiar, all Tamir.SharpSsh.dll / Sharpssh.dll's are NOT created equal. The majority of them gave me the message

Add-Type : Could not load file or assembly 'file:///C:\Users\User\Documents \WindowsPowerShell\Modules\SharpSSH\Tamir.SharpSSH.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)

I put this need for a specific version of the DLL down to being on a newer version of Windows with a newer version of .Net installed. Also remember you need to "unblock" the file by utilizing File Explorer, Right click to properties and choose unblock.

The working functions I found were here (Link2) utilizing a SharpSSH dll from here (Link3)

These allow me to connect to the Unix system with the Keyboard Interactive authentication, however I have been unable to successfully capture the output as it seems I am stuck in some kind of unix banner to the user.

For those working with "normal" SSH systems, the code at those two links will work great. I have used it against a standard RedHat installation and been happy with the results.

So now I have set aside the SharpSSH functions and am trying to get the newer SSH.NET dll component ( aka Renci.SshNet.dll ) working with Powershell.

The SSH.Net dll can be found here (Link4) and a good set of PowerShell functions built around it can be found here http://www.powershelladmin.com/wiki/SSH_from_PowerShell_using_the_SSH.NET_library

When trying to work with it and the Keyboard Interactive authentication, it continually returns the message:

Value cannot be null.\r\nParameter name: data

In this discussion (http://sshnet.codeplex.com/discussions/348102), swinster and Joel Bennett work on solving the problem, but eventually become stumped by the recurring error "Value cannot be null.\r\nParameter name: data".

This same error has previously hit StackOverflow utilizing the solution in that thread as its answer for VB. But the solution doesn't seem to work in PowerShell. (See the link for Joel Bennett's ideas on why it doesn't.)

Does anyone have any good working solutions for connecting via SSH to devices requiring Keyboard Interactive? Your help would be very much appreciated.

Note: I had to take out most of the links as I don't have enough rep points to post them. Sorry.

share

migration rejected from stackoverflow.com May 28 '13 at 6:55

This question came from our site for professional and enthusiast programmers. Votes, comments, and answers are locked due to the question being closed here, but it may be eligible for editing and reopening on the site where it originated.

closed as off topic by slhck May 28 '13 at 6:55

Questions on Super User are expected to relate to computer software or computer hardware within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

    
    
Link 1 - netcmdlets.com Link 4 - sshnet.codeplex.com –  Scott H May 28 '13 at 1:03
    
Don't know why this has been migrated from stackoverflow, but if you are into programming, take some commercial component which works fine. For example our SecureBlackbox ( eldos.com/sbb/net-ssh.php ) offers flexible support for keyboard-interactive and many other authentication types. –  Eugene Mayevski 'EldoS Corp May 28 '13 at 4:47
    
It's a programming question. Why was it migrated to SU ? –  JPBlanc May 28 '13 at 5:15
comments disabled on deleted / locked posts

1 Answer 1

I clearly miss something in your question, but I invoke commands on my linux box using plink. this is my c:\powershell\plink.ps1 :

function plink
{
  [CmdletBinding()]
  PARAM
  (
    [Parameter(Mandatory=$True)]
    [ValidateNotNullOrEmpty()]
    [string] $remoteHost,

    [Parameter(Mandatory=$True)]
    [ValidateNotNullOrEmpty()]
    [string] $login,

    [Parameter(Mandatory=$True)]
    [ValidateNotNullOrEmpty()]
    [string] $passwd,

    [Parameter(Mandatory=$True)]
    [ValidateNotNullOrEmpty()]
    [string] $command)

  & c:\MyTools\plink.exe -ssh $remoteHost -l $login -pw $passwd $command
  return
}

For example to restart my tomcat :

. 'c:\powershell\plink.ps1'

$remoteHost = "192.168.1.1"
$login = "root"

$command1 = "/opt/wd/apache-tomcat-6.0.32/bin/shutdown.sh "
$command2 = "cd /opt/wd/apache-tomcat-6.0.32/bin && ./start.sh"
$command3 = "ps -edalf | grep java"

$passwd = Read-Host "Password for $login"

write-host "Stopping Tomcat" -ForegroundColor DarkGreen
plink -remoteHost $remoteHost -login $login -command $command1 -passwd $passwd
Start-Sleep 10
write-host "Startting Tomcat" -ForegroundColor DarkGreen
plink -remoteHost $remoteHost -login $login -command $command2 -passwd $passwd
write-host "Result"-ForegroundColor DarkGreen
plink -remoteHost $remoteHost -login $login -command $command3 -passwd $passwd
share
add comment