2

I'm trying to execute a application console command (cslogin) on a Linux box from PowerShell. I used the SSH module from SSH.NET to access the Linux server. The following is a snapshot of my script, I'm able to establish the ssh session.

Import-Module SSH-Sessions
$user     = "user"
$password = "pass"
$hostname = "192.168.1.X"
C:\plink.exe -ssh -l $username -pw $password $hostname "cslogin"  

But once the cslogin command is executed the script hangs with the following message:

SEC054 A device has connected to, or disconnected from, a pseudo tty without authenticating

At this point if I hit the enter key I am able to get the application prompt, which is what I want. I am trying to understand why does my script hangs and how do I get around this issue.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
MrTriniAvi
  • 21
  • 3

2 Answers2

1

You only import the SSH-Sessions module, without actually using it. You then run PLink, that is not related to SSH.NET at all.


Pure SSH.NET solution is like:

Import-Module SSH-Sessions
New-SshSession -ComputerName "192.168.1.X" -Username "user" -Password "pass"
Invoke-SshCommand -InvokeOnAll "cslogin"

Other than that your PLink solution does the same. As it does not work, the SSH.NET solution above won't probably work either.

Your actual problem is that the application (cslogin) requires an interactive terminal (TTY). PLink by default does not allocate one. And I believe that SSH.NET does not either. With PLink, you can force TTY using -t switch:

$user     = "user"
$password = "pass"
$hostname = "192.168.1.X"
plink.exe -ssh -l $username -pw $password $hostname -t "cslogin"  

See Using the command-line connection tool Plink.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • Sorry about that, was trying to get this to work with both SSH module and plink and forget to remove the Import-Module SSH-Sessions code. – MrTriniAvi Apr 28 '15 at 16:51
  • Also tried with the plink -t parameter and got this ->bash: cslogin: command not found – MrTriniAvi Apr 28 '15 at 16:53
  • If you login with SSH terminal client (e.g. PuTTY), can you execute the `cslogin`? – Martin Prikryl Apr 29 '15 at 06:40
  • Yes, I can, whether I use putty, plink or SSH module I still get the "SEC054 A device has connected to, or disconnected from, a pseudo tty without authenticating" message. I can get pass the message by hiting the enter key – MrTriniAvi Apr 29 '15 at 11:54
  • I was thinking as a possible solution, if I can search the output for the message and then break to the next line of code. – MrTriniAvi Apr 29 '15 at 11:57
0

As far as I can see you're not actually using ssh.net here. Sure, you import the module but instead of using the New-SSHSession or Invoke-SSHCommand cmdlets you then run plink to connect and run cslogin. I confess I've not heard of that Linux command but bear in mind that plink expects to connect via SSH, execute a command and disconnect - so you won't get an interactive prompt.

You can either have plink run a script on the Linux server, or using the -m switch get plink to read a list of commands drone a file.

Alternatively you can setup a putty saved session then run plink to get interactive session but you might get some oddities in the powershell command window when it tries to interpret the output from plink.

for more info see this link

Graham Gold
  • 2,435
  • 2
  • 25
  • 34