Skip to content

paramiko.ssh_exception.SSHException: Channel closed. #513

Open

Description

@allen791210

here's the error msg
2015-04-17 3 20 07

I've googled the problem, paramiko.ssh_exception.SSHException: Channel closed.,
however, there isn't any appropriate solution to my problem.

Thus, I wanna to seek for the help of establishing the connection.

Anyone can give me some instructions of solving this problem?
Truly appreciate your help!

Activity

  1. Russell-Jones commented on Apr 18, 2015

    @Russell-Jones

    Could you provide a minimal code example that causes the problem? And describe what happens when you use normal (open)ssh? I suspect you need a try except block.

  2. allen791210 commented on Apr 18, 2015

    @allen791210
    Author

    hi, normal (open)ssh to the switch through command directly works well

    suspect you need a try except block.
    you mean i may try pass the error block?

    minimal code:
    here's the code in paramiko/channel.py
    def _wait_for_event(self):
    self.event.wait()
    assert self.event.is_set()
    if self.event_ready:
    return
    e = self.transport.get_exception()
    if e is None:
    e = SSHException('Channel closed.')
    raise e

    if it's not the code u want, plz let me know.
    thanks for your help.

  3. Russell-Jones commented on Apr 18, 2015

    @Russell-Jones

    I mean your code, not the code in paramiko, so the shortest thing like

    from paramiko import SSHClient
    
    # do stuff
    

    that causes the exception to happen. If "ryu" (whatever that is) is not your own code and you're not able to isolate the cause to a simple stand-alone script, it'd be best to talk to whoever wrote, supports or maintains it.

  4. allen791210 commented on Apr 18, 2015

    @allen791210
    Author

    hi, sorry for the dumb reply.
    yeah, i just use the library of the project "ryu"
    so i don't really understand what's wrong with paramiko.
    at least i'm sure that i can do ssh by command.

    i already google it and try find solutions for a long time.
    plz give me some instructions that i can try to solve this problem !
    it'll certainly help me a lot, thanks!

    here's my code:

    from ryu.lib.of_config.capable_switch import OFCapableSwitch
    import ryu.lib.of_config.classes as ofc
    
    sess = OFCapableSwitch(
            host='140.112.41.10',
            port=4294967293,
            username='admin',
            password='pass',
            unknown_host_cb=lambda host, fingeprint: True)
    
    csw = sess.get()
    for p in csw.resources.port:
            print p.resource_id, p.current_rate
    
    csw = sess.get_config('running')
    for p in csw.resources.port:
            print p.resource_id, p.configuration.admin_state
    

    here's the code of ryu/ryu/contrib/ncclient/transport/ssh.py and the web url
    1.

        # REMEMBER to update transport.rst if sig. changes, since it is hardcoded there
        def connect(self, host, port=830, timeout=None, unknown_host_cb=default_unknown_host_cb,
                    username=None, password=None, key_filename=None, allow_agent=True, look_for_keys=True):
    
            """Connect via SSH and initialize the NETCONF session. First attempts the publickey authentication method and then password authentication.
            To disable attempting publickey authentication altogether, call with *allow_agent* and *look_for_keys* as `False`.
            *host* is the hostname or IP address to connect to
            *port* is by default 830, but some devices use the default SSH port of 22 so this may need to be specified
            *timeout* is an optional timeout for socket connect
            *unknown_host_cb* is called when the server host key is not recognized. It takes two arguments, the hostname and the fingerprint (see the signature of :func:`default_unknown_host_cb`)
            *username* is the username to use for SSH authentication
            *password* is the password used if using password authentication, or the passphrase to use for unlocking keys that require it
            *key_filename* is a filename where a the private key to be used can be found
            *allow_agent* enables querying SSH agent (if found) for keys
            *look_for_keys* enables looking in the usual locations for ssh keys (e.g. :file:`~/.ssh/id_*`)
            """
    
            if username is None:
                username = getpass.getuser()
    
            sock = None
            for res in socket.getaddrinfo(host, port, socket.AF_UNSPEC, socket.SOCK_STREAM):
                af, socktype, proto, canonname, sa = res
                try:
                    sock = socket.socket(af, socktype, proto)
                    sock.settimeout(timeout)
                except socket.error:
                    continue
                try:
                    sock.connect(sa)
                except socket.error:
                    sock.close()
                    continue
                break
            else:
                raise SSHError("Could not open socket to %s:%s" % (host, port))
    
            t = self._transport = paramiko.Transport(sock)
            t.set_log_channel(logger.name)
    
            try:
                t.start_client()
            except paramiko.SSHException:
                raise SSHError('Negotiation failed')
    
            # host key verification
            server_key = t.get_remote_server_key()
            known_host = self._host_keys.check(host, server_key)
    
            fingerprint = _colonify(hexlify(server_key.get_fingerprint()))
    
            if not known_host and not unknown_host_cb(host, fingerprint):
                raise SSHUnknownHostError(host, fingerprint)
    
            if key_filename is None:
                key_filenames = []
            elif isinstance(key_filename, basestring):
                key_filenames = [ key_filename ]
            else:
                key_filenames = key_filename
    
            self._auth(username, password, key_filenames, allow_agent, look_for_keys)
    
            self._connected = True # there was no error authenticating
    
            c = self._channel = self._transport.open_session()
            c.set_name("netconf")
    (208)c.invoke_subsystem("netconf")
    
            self._post_connect()
    
    1. https://github.com/osrg/ryu/tree/master/ryu/
  5. Russell-Jones commented on Apr 18, 2015

    @Russell-Jones

    You should raise this on the ryu mailing list https://lists.sourceforge.net/lists/listinfo/ryu-devel , though check the archives first. https://github.com/osrg/ryu They can help you establish if it's a paramiko issue, or something to do with how you're using ryu.

    You didn't answer my question about what happens when you try a normal ssh session.

    Oh, and for IPv4 port numbers only go up to 65535, so the long number you have may not be valid: http://stackoverflow.com/questions/113224/what-is-the-largest-tcp-ip-network-port-number-allowable-for-ipv4
    The address suggests you're not using IPv6, though perhaps you should be if that's the port number you've been given? I don't know what the limits on ports in IPv6 are, having said that.

  6. allen791210 commented on Apr 18, 2015

    @allen791210
    Author

    sorry for not upload the latest code
    the port number is : 22 and it shows that i pass the authentication (successful) in the first msg

    sess = OFCapableSwitch(
            host='140.112.41.10',
            port=22,
            username='admin',
            password='pass',
            unknown_host_cb=lambda host, fingeprint: True)
    

    Actually, i already check all the problems in mailing list and post my problem as well. (still no any response) http://sourceforge.net/p/ryu/mailman/message/33860755/

    because the codes work well in a simulation environment, so i assume there maybe some problems with my computer settings, the python package, or the codes

    when I try a normal ssh session, like : ssh [email protected]
    then after i enter my password, i can get the permission into the management interface of switch
    like this

    Pica8@dev:~$ ssh 140.112.41.71 -l admin
    [email protected]'s password:
    admin@XorPlus$
    
  7. source-ram commented on Sep 1, 2017

    @source-ram

    Any fix available ?

  8. mrts commented on Dec 28, 2018

    @mrts

    In case you are trying to use SFTP this may be caused by the SFTP subsystem being disabled in the remote host.

    To enable the SFTP subsystem, uncomment the following line in /etc/ssh/sshd_config and restart the sshd service:

    Subsystem sftp /usr/lib/openssh/sftp-server
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions