Posh-SSH icon indicating copy to clipboard operation
Posh-SSH copied to clipboard

Same kind of issue: Posh-SSH with Cisco Switch #308

Open apagnott opened this issue 4 years ago • 28 comments

Hi,

I'm creating a powershell script based on posh-ssh module to apply a configuration to a liste of cisco switches..

I run into the same problem as in Posh-SSH with Cisco Switch #308... I get sometimes not everytime...

New-SSHSession -ComputerName $device -Port $remoteport -Credential $creds -AcceptKey:$true -KeepAliveInterval 1 -Verbose -ErrorAction Stop -ConnectionTimeout $conntimeout -OperationTimeout $opertimeout

I've tried with different values for $opertimeout and $connTimeout... but same issue... I try at the same time tu connect with putty and it works with it... How could I troubleshoot this ?

VERBOSE: Using SSH Username and Password authentication for connection.

Session operation has timed out

Thanks in advance for your help

apagnott avatar Nov 12 '20 11:11 apagnott

Anything on the logs on the cisco? teminal monitor I think is the command to see the debug info

Sent from my iPhone

On Nov 12, 2020, at 7:49 AM, apagnott [email protected] wrote:

 Hi,

I'm creating a powershell script based on posh-ssh module to apply a configuration to a liste of cisco switches..

I run into the same problem as in Posh-SSH with Cisco Switch #308... I get sometimes not everytime...

New-SSHSession -ComputerName $device -Port $remoteport -Credential $creds -AcceptKey:$true -KeepAliveInterval 1 -Verbose -ErrorAction Stop -ConnectionTimeout $conntimeout -OperationTimeout $opertimeout

I've tried with different values for $opertimeout and $connTimeout... but same issue... I try at the same time tu connect with putty and it works with it... How could I troubleshoot this ?

VERBOSE: Using SSH Username and Password authentication for connection.

Session operation has timed out

Thanks in advance for your help

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

darkoperator avatar Nov 12 '20 12:11 darkoperator

I've check the logs > sh logs .... but I dont see anything regarding the connexion attempt... maybe I have to check somewhere else on the switch... do you have an idea ? The strange thing is that for the same switch sometimes it works sometimes not.... how can I troubleshoot on powershell or .net side what coud go wrong ?

apagnott avatar Nov 12 '20 13:11 apagnott

It has been over a decade since I worked on Cisco gear but back in the ios 11 and 12 days debugging info was printed to the console

Sent from my iPhone

On Nov 12, 2020, at 9:24 AM, apagnott [email protected] wrote:

 I've check the logs > sh logs .... but I dont see anything regarding the connexion attempt... maybe I have to check somewhere eslse on the switch... do you have an idea ? The strange thing is that for the same switch sometimes it works sometimes not....

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

darkoperator avatar Nov 12 '20 15:11 darkoperator

How could I debug the powershell module ? Do you have a debug version?

apagnott avatar Nov 12 '20 20:11 apagnott

What I meant was on the Cisco Switch with a serial cable connected configure it with a high debug level and to print debug to the console and try to connect

On Nov 12, 2020, at 4:44 PM, apagnott [email protected] wrote:

How could I debug the powershell module ? Do you have a debug version?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/darkoperator/Posh-SSH/issues/354#issuecomment-726331838, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAD7IHXPKMPASURIFL4QAE3SPRCLPANCNFSM4TTF2EFA.

darkoperator avatar Nov 12 '20 21:11 darkoperator

I can definitely try that route and see if a clue of the problem can be identified on the switch, but...the issue is the same on other switches and as I said sometimes it works and sometimes I get the session operation time out exception...not consistent...my feeling is that the problem is on the pc running the powershell command...what can look at on the PC in order to investigate? Could I test the underlying interface and see if the error returned gives me more clues?

apagnott avatar Nov 13 '20 00:11 apagnott

Reading through other opened issues I found this one... that could be the same I'm facing

Cisco Router frequent New-SSHSession : Session operation has timed out #340

apagnott avatar Nov 13 '20 10:11 apagnott

I wondering if I have to use ssh.client that is referenced here... I didn't and it worked so maybe the built in ssh.client library is already in .net framework 4. Could you help on this ? HOw can force the posh-module to use this https://www.nuget.org/packages/ssh.net/ ?

apagnott avatar Nov 20 '20 15:11 apagnott

@apagnott How do you run your script? via ISE or from powershell command line? I have recently noticed that the behavior is different considering how I do run my script. From the ISE I always face strange errors. Would that be the case for you?

reybanger avatar Nov 20 '20 15:11 reybanger

I use ISE...I m gonna try to run my script with powershell.exe

Thanks for trying to help me .... Do you know how to use ssh.net and install it? I did try without it...it seems to be included in .net framework...or I dont understand how this ssh.net is used by posh....

Le Fri, 20 Nov 2020 07:58:53 -0800, reybanger a écrit :

@apagnott How do you run your script? via ISE or from powershell command line? I have recently noticed that the behavior is different considering how I do run my script. From the ISE I always face strange errors. Would that be the case for you?

-- Sent using Dekko from my Ubuntu device

apagnott avatar Nov 20 '20 17:11 apagnott

SSH.Net http://ssh.net/ is just a library, you can download the code from Github and compile it in Visual Studio for the framework you need. I’m using the latest version with some additional fixes from PRs that are in the GitHub.

On Nov 20, 2020, at 1:30 PM, apagnott [email protected] wrote:

I use ISE...I m gonna try to run my script with powershell.exe

Thanks for trying to help me .... Do you know how to use ssh.net and install it? I did try without it...it seems to be included in .net framework...or I dont understand how this ssh.net is used by posh....

Le Fri, 20 Nov 2020 07:58:53 -0800, reybanger a écrit :

@apagnott How do you run your script? via ISE or from powershell command line? I have recently noticed that the behavior is different considering how I do run my script. From the ISE I always face strange errors. Would that be the case for you?

-- Sent using Dekko from my Ubuntu device — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/darkoperator/Posh-SSH/issues/354#issuecomment-731302060, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAD7IHU3VR4O3TASHYKGAELSQ2RUZANCNFSM4TTF2EFA.

darkoperator avatar Nov 20 '20 17:11 darkoperator

Ok I thought posh-ssh is using it....so it is not ? the module seems to work without it...

To get back to my issue .... I m not the only one facing it? Could it be related to the .net framework insralled on my box? Is operation timeout parameters really implemented in posh?

Le Fri, 20 Nov 2020 09:40:29 -0800, Carlos Perez a écrit :

SSH.Net http://ssh.net/ is just a library, you can download the code from Github and compile it in Visual Studio for the framework you need. I’m using the latest version with some additional fixes from PRs that are in the GitHub.

On Nov 20, 2020, at 1:30 PM, apagnott [email protected] wrote:

I use ISE...I m gonna try to run my script with powershell.exe

Thanks for trying to help me .... Do you know how to use ssh.net and install it? I did try without it...it seems to be included in .net framework...or I dont understand how this ssh.net is used by posh....

Le Fri, 20 Nov 2020 07:58:53 -0800, reybanger a écrit :

@apagnott How do you run your script? via ISE or from powershell command line? I have recently noticed that the behavior is different considering how I do run my script. From the ISE I always face strange errors. Would that be the case for you?

-- Sent using Dekko from my Ubuntu device — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/darkoperator/Posh-SSH/issues/354#issuecomment-731302060, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAD7IHU3VR4O3TASHYKGAELSQ2RUZANCNFSM4TTF2EFA.

-- Sent using Dekko from my Ubuntu device

apagnott avatar Nov 20 '20 18:11 apagnott

I use the library, just not the old one in the nugget repo. It is outdated and has some bugs

On Nov 20, 2020, at 2:30 PM, apagnott [email protected] wrote:

Ok I thought posh-ssh is using it....so it is not ? the module seems to work without it...

To get back to my issue .... I m not the only one facing it? Could it be related to the .net framework insralled on my box? Is operation timeout parameters really implemented in posh?

Le Fri, 20 Nov 2020 09:40:29 -0800, Carlos Perez a écrit :

SSH.Net http://ssh.net/ is just a library, you can download the code from Github and compile it in Visual Studio for the framework you need. I’m using the latest version with some additional fixes from PRs that are in the GitHub.

On Nov 20, 2020, at 1:30 PM, apagnott [email protected] wrote:

I use ISE...I m gonna try to run my script with powershell.exe

Thanks for trying to help me .... Do you know how to use ssh.net and install it? I did try without it...it seems to be included in .net framework...or I dont understand how this ssh.net is used by posh....

Le Fri, 20 Nov 2020 07:58:53 -0800, reybanger a écrit :

@apagnott How do you run your script? via ISE or from powershell command line? I have recently noticed that the behavior is different considering how I do run my script. From the ISE I always face strange errors. Would that be the case for you?

-- Sent using Dekko from my Ubuntu device — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/darkoperator/Posh-SSH/issues/354#issuecomment-731302060, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAD7IHU3VR4O3TASHYKGAELSQ2RUZANCNFSM4TTF2EFA.

-- Sent using Dekko from my Ubuntu device — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/darkoperator/Posh-SSH/issues/354#issuecomment-731338402, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAD7IHR2C7INFOHWMFDF7QLSQ2YWFANCNFSM4TTF2EFA.

darkoperator avatar Nov 20 '20 18:11 darkoperator

How could I invetigate on client (module) side.... if the remote ssh host is waiting for anything ? Maybe the issue is due to a bug in this ssh.net library... I would like to check that can you help me with a command I could use ? Moreover, when I have my issue, I try later and it works..... so it's like a number of subsequent calls to different remote host is blocked... or something like that

apagnott avatar Nov 24 '20 14:11 apagnott

Hi. I'm facing same issue while working with cisco gear via posh-ssh. Connection works in about 1/10 times. Wireshark shows that in success case server (cisco switch) starts key exchange init; In failure cases there is no key exchange at all. This explains timeout errors. Seems like it's Cisco problem, but I'm not sure. I'm not even sure that this comment would be helpful.

Genfilf avatar Nov 28 '20 23:11 Genfilf

Sadly not much I can do since I do not own or have the skill to modify the library to work with Cisco version of SSH :(

Sent from my iPhone

On Nov 28, 2020, at 7:33 PM, Genfilf [email protected] wrote:

 Hi. I'm facing same issue while working with cisco gear via posh-ssh. Connection works in about 1/10 times. Wireshark shows that in success case server (cisco switch) starts key exchange init; In failure cases there is no key exchange at all. This explains timeout errors. Seems like it's Cisco problem, but I'm not sure. I'm not even sure that this comment would be helpful.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

darkoperator avatar Nov 29 '20 00:11 darkoperator

Thanks for reply. I see some issues in SSH.NET repo that might be related, so it might be a trouble with the library that used in module, or the Cisco SSH itself (but I'm not sure since I'm not much into programming).

Have a nice day!

Genfilf avatar Nov 29 '20 00:11 Genfilf

I've got the same issue. However, i might have some additional information that could be of interest.

The module used to work just fine in this scenario:

  • Server: Windows Server 2008 R2
  • Posh-SSH: version 2.2

Obviously we've migrated the server because it's end-of-life. Our new setup has the same issue as described (only 1 in 10 connections work):

  • Server: Windows Server 2019
  • Posh-SSH: version 2.3 (since the 2.2 version doesn't work on server 2019)

Maybe someone with the right skills can look at the things that have changed? Since i don't know where to begin.

Patrick92x avatar Dec 11 '20 14:12 Patrick92x

On it was mostly me renaming the library so it stopped conflicting with MS including it for some weird storage migration component they included.

On Dec 11, 2020, at 10:26 AM, Patrick [email protected] wrote:

I've got the same issue. However, i might have some additional information that could be of interest.

The module used to work just fine in this scenario:

Server: Windows Server 2008 R2 Posh-SSH: version 2.2 Obviously we've migrated the server because it's end-of-life. Our new setup has the same issue as described (only 1 in 10 connections work):

Server: Windows Server 2019 Posh-SSH: version 2.3 (since the 2.2 version doesn't work on server 2019) Maybe someone with the right skills can look at the things that have changed? Since i don't know where to begin.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/darkoperator/Posh-SSH/issues/354#issuecomment-743222181, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAD7IHSYYVSSV5BULKHJCXTSUITZBANCNFSM4TTF2EFA.

darkoperator avatar Dec 11 '20 14:12 darkoperator

@darkoperator Thanks for the reply. After a day of testing during the holiday I've found the issue.

I've tested multiple versions of Posh-SSH on Windows Server 2012 (since all versions work over there because it doesn't conflict). The conclusion:

  • Version 2.2 works fine
  • Version 2.3 gives a timeout to some devices at random (even if its the same device)

Issue:

  • Posh-SSH version 2.2 uses the "Renci.SshNet.dll" version 2016.1.0-beta2
  • Posh-SSH version 2.3 uses the "Renci.SshNet.dll" (renamed to Renci.SshNetPS.dll) version 2016.1.0

Workaround:

  • When i replace the Renci.SshNetPS.dll with the 2016.1.0-beta2 version the random timeouts don't happen.

I've also done some other debugging on the enddevice, and with wireshark. No real differences in the negotiation as far as i can tell. I guess the only thing left to do is submit to the SSH Repo.

P.S. It was nice to meet you at PSConf 2019 ;)

Patrick92x avatar Dec 27 '20 22:12 Patrick92x

Interesting I know there where some changes in version information around OpenSSH needing clients to report version info. Wonder if Cisco devices since they forked and modified for their devices OpenSSH have a problem with that.

darkoperator avatar Dec 27 '20 23:12 darkoperator

It sure is weird since it's so inconsistent.

The only additional info i have is the following:

  • both versions show simular traffic within wireshark
  • when the connection fails it never started the key-exchange (thus the timeout)

So the question is... Why does it sometimes start the key exchange, and in other times is does not...

Unfortunately the debug on the Cisco side for SSH is just like in #340 so i have no clue.

Patrick92x avatar Dec 27 '20 23:12 Patrick92x

Please test the alpha release to see if issue is resolved https://github.com/darkoperator/Posh-SSH/releases/tag/3.0.0-Alpha

This is a major release with breaking changes and it is cross platform for the latest version of powershell.

darkoperator avatar Feb 01 '21 10:02 darkoperator

I still have the same issue with 3.0.0. The only way I can get it to work still is when i replace the Renci.SshNetPS.dll with the 2016.1.0-beta2 version

thewizard1002 avatar Feb 25 '21 15:02 thewizard1002

Sadly it is an issue with he library and not the PowerShell module. I opened a Issue in their project. So far no reply from the library author.

darkoperator avatar Feb 25 '21 15:02 darkoperator

can you tell me the exact operation you are doing for this workaround?

Do you know the project for this library) page so that I could also join to mention / document the isdie

Le Thu, 25 Feb 2021 07:11:56 -0800, thewizard1002 a écrit :

I still have the same issue with 3.0.0. The only way I can get it to work still is when i replace the Renci.SshNetPS.dll with the 2016.1.0-beta2 version

-- Sent using Dekko from my Ubuntu device

apagnott avatar Feb 26 '21 12:02 apagnott

can you tell me the exact operation you are doing for this workaround?

See the workaround details I've described in #340

Patrick92x avatar Feb 26 '21 12:02 Patrick92x

Version 3.1.2 includes the latest version of SSH.NET, which should address this.

darkoperator avatar Jan 03 '24 00:01 darkoperator