Error in connecting (SSH) remote server (Mongo DB) through jump server using Paramico in python Script

I am trying to connect a Mongo DB server through jump server in my python script using Paramico on a AWS instance.

Let me explain how i connect to Mongo DB server on terminal on AWS:

    $ssh -i Key.pem harman@ # I ssh on Jump server with this command

After login on to Jump server I use following command to SSH on Mongo DB server:

    $ssh ctpms-lmini1-Jsct1

here i do not require any authentication. No username, password or key is required.

Now i have to establish the same connection with python scrips. Here is my


    #Connect to Jump Server
    Jump_client = paramiko.SSHClient()

    Jump_client.connect(hostname='', port=22,
    username='harman', key_filename='key.pem', banner_timeout=10)

I am successfully able to connect to jump server and able to run :


Establish a channel between Mongo db server and Jump server:

    chan = client.get_transport()
    dest_addr = ('', 22) #Mongo DB server IP#
    local_addr = ('', 22) #Jump server IP#
    mongochannel = chan.open_channel("direct-tcpip", dest_addr,local_addr) 

This was also succefull mongochannel is returning following:

    <paramiko.Channel 0 (open) window=2097152 in-buffer=23 -> <paramiko.Transport at 0x7a952f90L (cipher aes128-ctr, 128 bits) (active; 1 open channel(s))>>

Now I am trying use mongochannel as socket and creating new session but getting error:

    mongo_client = paramiko.SSHClient()
    mongo_client.connect(hostname='', sock=mongochannel) 

Here is the error:

    EOFError                                  Traceback (most recent call last)
   <ipython-input-26-2000cff93e10> in <module>()
   2 client1.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  3 client1.load_system_host_keys()
   ----> 4 client1.connect(hostname='', sock=vmchannel)

   /usr/local/lib/python2.7/dist-packages/paramiko/client.pyc in connect(self, hostname, port, username, password, pkey, key_filename, timeout, allow_agent, look_for_keys, compress, sock, gss_auth, gss_kex, gss_deleg_creds, gss_host, banner_timeout, auth_timeout, gss_trust_dns, passphrase)
395             sec_opts.key_types = [keytype] + other_types
  --> 397         t.start_client(timeout=timeout)
399         # If GSS-API Key Exchange is performed we are not required to check the

 /usr/local/lib/python2.7/dist-packages/paramiko/transport.pyc in start_client(self, event, timeout)
585                 e = self.get_exception()
586                 if e is not None:
  --> 587                     raise e
588                 raise SSHException("Negotiation failed.")
589             if event.is_set() or (


As I mentioned earlier I do not require any username, password or key for mongodb. Please suggest.

I also tried jumpssh for this purpose but it also did not work.Here is the code:

   from jumpssh import SSHSession 
   gateway_session = SSHSession('', 'test_user', proxy_transport=None, private_key_file='test.pem',

port=22, password=None, missing_host_key_policy=None, compress=False)

Jump server connection worked fine but following code for mongodb server is giving error:

  remote_session = gateway_session.get_remote_session('','test_user')


  ConnectionError                           Traceback (most recent call last)
  <ipython-input-66-10b1b39a1f86> in <module>()
  ----> 1 remote_session = gateway_session.get_remote_session('','harman')

  /usr/local/lib/python2.7/dist-packages/jumpssh/session.pyc in get_remote_session(self, host, username, retry, private_key_file, port, password, retry_interval, compress)
496                                     password=password,
497                                     compress=compress).open(retry=retry,
 --> 498                                                             retry_interval=retry_interval)
500         # keep reference to opened session, to be able to reuse it later

   /usr/local/lib/python2.7/dist-packages/jumpssh/session.pyc in open(self, retry, retry_interval)
159                 else:
160                     raise exception.ConnectionError("Unable to connect to '%s:%s' with user '%s'"
  --> 161                                                     % (, self.port, self.username), original_exception=ex)
163         # Get the client's transport

  ConnectionError: Unable to connect to '' with user 'test_user': [Errno 104] Connection reset by peer

Please note I also tried using same pem file for mongodb server that I use for jumpserver but it did not help.

Please provide your suggestions to resolve this.

Regards, Bharat