SchoofsKelvin / vscode-sshfs

Extension for Visual Studio Code: File system provider using SSH
GNU General Public License v3.0
543 stars 36 forks source link

SSH to Juniper or Cisco Devices #327

Open kellymcdo opened 2 years ago

kellymcdo commented 2 years ago

Hi Kelvin,

This is a fantastic product you have. Well done, and thank you!

As a network engineer, I would love the ability to also use it as more of an organizational tool to facilitate my SSH process for network gear.

Currently, it works great connecting to my linux boxes - But when I try to use it to SSH directly to any Juniper or Cisco devices, I get a terminal error: The terminal process failed to launch (exit code: 1) image

It seems to make the connection and authenticate with no issues. I tried adding the -CHECK_HOME flag thinking it was getting tripped up there but to no avail. I have tried different terminals; CMD, powershell, GIT BASH, etc.

Debug is from an older Cisco router, but I have the same experience on newer gear and new Juniper routers (IOS-XE, IOS-XR, JUNOS).

DEBUG CISCO.txt

Let me know if I can provide any further info.

Thanks!

SchoofsKelvin commented 2 years ago

Does SFTP work? And if not, is it supposed to? I don't really expect a router/switch to need SFTP-able file storage, but I might be underestimating them. It shouldn't show that kind of terminal error if all you're doing is trying to access files.

Your log indicates that when it comes to creating a terminal, that your devices don't support/allow that:

The command you have entered is available in the IOS.sh.
However, the shell is currently disabled. You can enable
it on this terminal by typing
   'term shell'
You can also enable it for all terminals by configuring the
   'shell processing full'
command. There is additional information in the man command.
For more information, enable shell, and then enter:
'man IOS.sh'
kellymcdo commented 2 years ago

Thanks for the quick response Kelvin,

SFTP does work on these devices, but your are correct in thinking that is not really needed (at least for my current plans). I was hoping I could use this tool to set up a pretty list of my SSH sessions and ignore the FS side of it for these devices for now (aka a better looking/customizable MTPutty).

That IOS.sh log message comes from one of the Cisco devices after it has opened a terminal when it tries to run $SHELL - these devices usually have a method to shell into the underlying system, but the command for that varies, and is out of scope for what I would like to accomplish.

I should mention; when I try to connect, it often brings up a terminal for a split second where I can even see the login banner for the router/switch but then closes instantly with the popup error I attached (exit code:1).

I am attaching another debug log from one of the Juniper devices - seems pretty much the same other than the output from the $SHELL input.

DEBUG JUNIPER.txt *edited with correct debug log

kellymcdo commented 2 years ago

While the result I get from both Cisco and Juniper routers is the same, there is a big difference in the debug logs.

I am noticing that on the Cisco device, the session seems to fail out from no response:

[ERROR]   [createConnection(cisco1,config)] Error calculating ShellConfig: Error: Could not get $SHELL
Error: Could not get $SHELL
    at c:\Users\username\.vscode\extensions\kelvin.vscode-sshfs-1.24.1\dist\extension.js:11:16622
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async d._createConnection (c:\Users\username\.vscode\extensions\kelvin.vscode-sshfs-1.24.1\dist\extension.js:11:16357)
Logged at:
    at c:\Users\username\.vscode\extensions\kelvin.vscode-sshfs-1.24.1\dist\extension.js:11:16892
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async d._createConnection (c:\Users\username\.vscode\extensions\kelvin.vscode-sshfs-1.24.1\dist\extension.js:11:16357)
Reported by logger createConnection(cisco1,config)
[DEBUG]   [ssh2(cisco1)] DEBUG: Outgoing: Writing CHANNEL_OPEN (1, session)
[ERROR]   [createConnection(cisco1,config)] Could not detect home directory
Logged at:

Reported by logger createConnection(cisco1,config)

>[WARNING] [createConnection(cisco1,config)] Error: No response from server

Logged at:

Reported by logger createConnection(cisco1,config)
[WARNING] [createConnection(cisco1,config)] The CHECK_HOME flag is disabled, default to '/' and ignore the error
Logged at:

Reported by logger createConnection(cisco1,config)
[DEBUG]   [createConnection(cisco1,config)] Home path: 
[DEBUG]   [createConnection(cisco1,config)] Environment: []
[DEBUG]   Starting shell for cisco1: $SHELL
[ERROR]   Error starting SSH terminal:

>Error: Not connected

Error: Not connected
    at T.exec (c:\Users\username\.vscode\extensions\kelvin.vscode-sshfs-1.24.1\dist\14f8.extension.js:1:258048)
Caused by toPromise:
    at Object.open (c:\Users\username\.vscode\extensions\kelvin.vscode-sshfs-1.24.1\dist\extension.js:11:4284)
    at startSendingEvents (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:96:38185)
    at C.$startExtensionTerminal (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:96:42973)
    at t._doInvokeHandler (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:99:13802)
    at t._invokeHandler (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:99:13486)
    at t._receiveRequest (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:99:12148)
    at t._receiveOneMessage (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:99:10826)
    at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:99:8922
    at u.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:66:1712)
    at r.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:74:18942)
Logged at:
    at Object.open (c:\Users\username\.vscode\extensions\kelvin.vscode-sshfs-1.24.1\dist\extension.js:11:4989)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
[INFO]    Closing connection to 'cisco1' with 'Idle with no active filesystems/terminals' as reason

Where as on the Juniper device, the terminal session just closes seemingly out of the blue:

[DEBUG]   [createConnection(juniper1,config)] Home path: 
[DEBUG]   [createConnection(juniper1,config)] Environment: []
[DEBUG]   Starting shell for juniper1: $SHELL
[DEBUG]   [ssh2(juniper1)] DEBUG: Outgoing: Writing CHANNEL_OPEN (2, session)
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKET
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: Decrypting
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: pktLen:28,padLen:10,remainLen:16
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATA
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: Decrypting
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: HMAC size:32
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATAVERIFY
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: Verifying MAC
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_OPEN_CONFIRMATION
[DEBUG]   [ssh2(juniper1)] DEBUG: Outgoing: Writing CHANNEL_REQUEST (0, pty-req)
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETBEFORE (expecting 16)
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKET
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: Decrypting
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: pktLen:12,padLen:6,remainLen:0
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATA
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: HMAC size:32
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATAVERIFY
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: Verifying MAC
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_SUCCESS (2)
[DEBUG]   [ssh2(juniper1)] DEBUG: Outgoing: Writing CHANNEL_REQUEST (0, exec)
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETBEFORE (expecting 16)
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKET
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: Decrypting
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: pktLen:28,padLen:18,remainLen:16
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATA
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: Decrypting
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: HMAC size:32
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATAVERIFY
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: Verifying MAC
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_WINDOW_ADJUST (2, 2097152)
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETBEFORE (expecting 16)
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKET
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: Decrypting
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: pktLen:12,padLen:6,remainLen:0
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATA
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: HMAC size:32
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATAVERIFY
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: Verifying MAC
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_SUCCESS (2)
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETBEFORE (expecting 16)
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKET
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: Decrypting
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: pktLen:60,padLen:16,remainLen:48
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATA
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: Decrypting
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: HMAC size:32
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATAVERIFY
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: Verifying MAC
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_DATA (2)
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETBEFORE (expecting 16)
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKET
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: Decrypting
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: pktLen:12,padLen:6,remainLen:0
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATA
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: HMAC size:32
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATAVERIFY
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: Verifying MAC
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_EOF (2)
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETBEFORE (expecting 16)
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKET
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: Decrypting
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: pktLen:44,padLen:18,remainLen:32
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATA
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: Decrypting
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: HMAC size:32
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATAVERIFY
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: Verifying MAC
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_REQUEST (2, exit-status)

> [DEBUG]   Terminal session closed: {"code":0,"status":"open"}

[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETBEFORE (expecting 16)
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKET
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: Decrypting
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: pktLen:12,padLen:6,remainLen:0
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATA
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: HMAC size:32
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATAVERIFY
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: Verifying MAC
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_CLOSE (2)
[DEBUG]   [ssh2(juniper1)] DEBUG: Outgoing: Writing CHANNEL_CLOSE (0)
[DEBUG]   [ssh2(juniper1)] DEBUG: Parser: IN_PACKETBEFORE (expecting 16)
[INFO]    Closing connection to 'juniper1' with 'Idle with no active filesystems/terminals' as reason

Both devices have the same resulting error from vscode "The terminal process failed to launch (exit code: 1)."

Not sure what else the stable connection is dependent on. The SSH session seems to establish just fine but then fails. SSH directly from any terminal to these devices works fine.