paramiko.SSHException: Channel closed

Created on 15 May 2019  路  4Comments  路  Source: paramiko/paramiko

I am a complete beginner with paramiko and I am trying to run a command on an Alcatel OS6450 switch.

I can make ssh with rsa key (no password) without problem on this switch

ssh [email protected] 

Welcome to the Alcatel-Lucent OmniSwitch 6450
Software Version 6.6.5.63.R02 GA, December 16, 2014. 

Copyright(c), 1994-2014 Alcatel-Lucent. All Rights reserved.

OmniSwitch(TM) is a trademark of Alcatel-Lucent registered
in the United States Patent and Trademark Office.

SW001-> dir

Listing Directory /flash:

-rw       310 Mar  1  2000 boot.params 
drw      2048 Sep  3  2002 certified/
drw      2048 Sep  3  2002 working/
-rw     64000 May  7 10:20 swlog1.log 
-rw     64000 May 21  2000 swlog2.log 
-rw        12 Jan  1  2001 boot.slot.cfg 
drw      2048 Jan  1  2001 switch/
drw      2048 Jan  1  2001 network/
-rw        20 Jan  1  2001 installed 

    55750656 bytes free

SW001-> exit
Connection to 192.168.1.1 closed.

I can't run directly a command from ssh

ssh [email protected] dir
exec request failed on channel 0

Then i made a try with paramiko with some scripts found on the net, all give me the same error :

import paramiko
k = paramiko.RSAKey.from_private_key_file("/home/pascal/.ssh/id_rsa")
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print "connecting"
c.connect( hostname = "192.168.1.1", username = "admin", pkey = k )
print "connected"
commands = [ "show spantree ports blocking" ]
for command in commands:
    print "Executing {}".format( command )
    stdin , stdout, stderr = c.exec_command(command)
    print stdout.read()
    print( "Errors")
    print stderr.read()
c.close()


This script give me this message :

connected
Executing show spantree ports blocking
Traceback (most recent call last):
  File "test.py", line 11, in <module>
    stdin , stdout, stderr = c.exec_command(command)
  File "/usr/lib/python2.7/dist-packages/paramiko/client.py", line 499, in exec_command
    chan.exec_command(command)
  File "/usr/lib/python2.7/dist-packages/paramiko/channel.py", line 72, in _check
    return func(self, *args, **kwds)
  File "/usr/lib/python2.7/dist-packages/paramiko/channel.py", line 257, in exec_command
    self._wait_for_event()
  File "/usr/lib/python2.7/dist-packages/paramiko/channel.py", line 1208, in _wait_for_event
    raise e
paramiko.ssh_exception.SSHException: Channel closed.

Is there a solution ?
Thanks for your help

Most helpful comment

Hi

In order for SSHConnection.exec_command() to work, an SSH server has to support exec_command channels, and not every server does. In this case, the server probably rejects the request to open the channel of this type, hence for paramiko it looks like the Channel is closed.

To my knowledge, the only way to interact with such servers is to use invoke_shell().

Most ssh servers running on network switches won't have the feature implemented. That's also the reason behind ssh user@host command not working

All 4 comments

Hi

In order for SSHConnection.exec_command() to work, an SSH server has to support exec_command channels, and not every server does. In this case, the server probably rejects the request to open the channel of this type, hence for paramiko it looks like the Channel is closed.

To my knowledge, the only way to interact with such servers is to use invoke_shell().

Most ssh servers running on network switches won't have the feature implemented. That's also the reason behind ssh user@host command not working

I am trying to do some sftp operation with paramiko and while doing so I am getting same error. Below is my code, what could be the reason ?

1 import paramiko
2 paramiko.util.log_to_file(".paramiko.log")
3
4 # Open a transport
5 host,port = "10.50.156.102",22
6 transport = paramiko.Transport((host,port))
7
8 # Auth
9 username,password = "root","x"
10 transport.connect(None,username,password)
11
12 # Go!
13 print transport
14 sftp = paramiko.SFTPClient.from_transport(transport)
15
16 # Download
17 filepath = "/etc/passwd"
18 localpath = "/tmp/remotepasswd"
19 sftp.get(filepath,localpath)
20
21 # Close
22 if sftp: sftp.close()
23 if transport: transport.close()

# python mytest.py
Traceback (most recent call last):
File "mytest.py", line 16, in
sftp = paramiko.SFTPClient.from_transport(transport)
File "/home/sagk/dev/paramiko/paramiko/sftp_client.py", line 169, in from_transport
chan.invoke_subsystem("sftp")
File "/home/sagk/dev/paramiko/paramiko/channel.py", line 72, in _check
return func(self, args, *kwds)
File "/home/sagk/dev/paramiko/paramiko/channel.py", line 283, in invoke_subsystem
self._wait_for_event()
File "/home/sagk/dev/paramiko/paramiko/channel.py", line 1226, in _wait_for_event
raise e
paramiko.ssh_exception.SSHException: Channel closed.

@gksalil i am having the same problem in front of me. it is related to the sftp server on the Omniswitch. It seems to be disabled. Some blog posts indicated one should do scp-sftp to enable it, but that command does not exist.

Since it's your own code, I hope you can find a good workaround.
The problem is, in any case, the switch.

I've been dealing with intermittent channel closed failures. I regularly transfers multiple files per day (to the same server) but every now and again the process fails with the following error:

 File "/home/file-transfers/lib/python3.9/site-packages/paramiko/sftp_client.py", line 169, in from_transport
   chan.invoke_subsystem("sftp")
 File "/home/file-transfers/lib/python3.9/site-packages/paramiko/channel.py", line 72, in _check
   return func(self, *args, **kwds)
 File "/home/file-transfers/lib/python3.9/site-packages/paramiko/channel.py", line 283, in invoke_subsystem
   self._wait_for_event()
 File "/home/file-transfers/lib/python3.9/site-packages/paramiko/channel.py", line 1226, in _wait_for_event
   raise e
paramiko.ssh_exception.SSHException: Channel closed.

Any idea what might be going on? Unfortunately, I have no view of anything happening on the server as it is out of my control.

Was this page helpful?
0 / 5 - 0 ratings