darkoperator / darkoperator/Posh-SSH

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

Open
#340 20 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PowerShell
Stars
1.1k
Forks
222
PR merge metrics
No merged PRs in 30d

Description

Hi,

While connecting to a Cisco Router with the following command:

New-SSHSession -ComputerName $Device -ConnectionTimeout 15 -AcceptKey -Credential $credential -Verbose -ErrorAction Stop

Sometimes it succeeds and the connection is working, but most of the time the connection fails with:

New-SSHSession : Session operation has timed out
At D:\Scripts\Get-DeviceConfiguration.ps1:104 char:16
+                 $session = New-SSHSession -ComputerName $Device -ConnectionTimeout 15 ...
+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationTimeout: (Renci.SshNet.SshClient:SshClient) [New-SSHSession], SshOperationTimeoutException
    + FullyQualifiedErrorId : SSH.NewSshSession

When i monitor on the Cisco Router with "debug ip ssh", i get the following on success:

Jul 28 13:57:05.701: SSH1: starting SSH control process
Jul 28 13:57:05.701: SSH1: sent protocol version id SSH-2.0-Cisco-1.25
Jul 28 13:57:05.701: SSH1: protocol version id is - SSH-2.0-Renci.SshNet.SshClient.0.0.1
Jul 28 13:57:05.702: SSH2 1: kexinit sent: kex algo = diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1
Jul 28 13:57:05.702: SSH2 1: Server certificate trustpoint not found. Skipping hostkey algo = x509v3-ssh-rsa
Jul 28 13:57:05.702: SSH2 1: kexinit sent: hostkey algo = ssh-rsa
Jul 28 13:57:05.702: SSH2 1: kexinit sent: encryption algo = aes128-ctr,aes192-ctr,aes256-ctr
Jul 28 13:57:05.702: SSH2 1: kexinit sent: mac algo = hmac-sha2-256,hmac-sha2-512,hmac-sha1,hmac-sha1-96
Jul 28 13:57:05.702: SSH2 1: send:packet of  length 312 (length also includes padlen of 4)
Jul 28 13:57:05.702: SSH2 1: SSH2_MSG_KEXINIT sent
etc...

And when the connection fails:

Jul 28 14:45:08.975: SSH3: starting SSH control process
Jul 28 14:45:08.975: SSH3: sent protocol version id SSH-2.0-Cisco-1.25
Jul 28 14:45:23.977: SSH3: protocol version id is - SSH-2.0-Renci.SshNet.SshClient.0.0.1
Jul 28 14:45:23.977: SSH2 3: kexinit sent: kex algo = diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1
Jul 28 14:45:23.977: SSH2 3: Server certificate trustpoint not found. Skipping hostkey algo = x509v3-ssh-rsa
Jul 28 14:45:23.977: SSH2 3: kexinit sent: hostkey algo = ssh-rsa
Jul 28 14:45:23.977: SSH2 3: kexinit sent: encryption algo = aes128-ctr,aes192-ctr,aes256-ctr
Jul 28 14:45:23.977: SSH2 3: kexinit sent: mac algo = hmac-sha2-256,hmac-sha2-512,hmac-sha1,hmac-sha1-96
Jul 28 14:45:23.978: SSH2 3: send:packet of  length 312 (length also includes padlen of 4)
Jul 28 14:45:23.978: SSH2 3: send:packet of  length 72 (length also includes padlen of 7)
Jul 28 14:45:24.078: SSH3: Session disconnected - error 0x00

You can see that when the connection is successfull, everything is being processed within the same second. But when the connection fails, it takes the Timeout (in this case 15 seconds) before it logs the protocol version id of the client and then disconnects.

The Verbose output in Powershell on success is:

VERBOSE: Using SSH Username and Password authentication for connection.
VERBOSE: Fingerprint for ***************: *:**:**:**:*:*:**:**:**:**:**:**:**:**:**:**
VERBOSE: Fingerprint matched trusted fingerprint for host ***************

And on failure:

VERBOSE: Using SSH Username and Password authentication for connection.

I'm using Posh-SSH version 2.3-beta1 on Windows Server 2012 R2.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the New-SSHSession invocation in D:\Scripts\Get-DeviceConfiguration.ps1 and reproduce the intermittent timeout against the Cisco Router. Compare the Cisco "debug ip ssh" output and PowerShell verbose output for successful and failed connections, focusing on the 15-second ConnectionTimeout. Done means identifying and resolving the cause of the failed session operation.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.