Community discussions

MikroTik App
 
User avatar
hxvxt2
just joined
Topic Author
Posts: 1
Joined: Fri Jan 14, 2022 9:39 am

Connection via Paramiko failing but works fine with SSH login from CLI

Fri Jan 14, 2022 9:55 am

Hi There,

I'm trying to connect to a router via the Python Paramiko library but I'm getting an 'Authentication failed' error. The same set of credentials works when I SSH from the command line. What am I missing? Is there anything additional that I need to set on the router in order to work with Paramiko?


In [92]: import paramiko

In [93]: client=paramiko.SSHClient()

In [94]: client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

In [95]: client.connect(hostname=target, username=username, password=password)
---------------------------------------------------------------------------
AuthenticationException                   Traceback (most recent call last)
<ipython-input-95-c070ba5b0370> in <module>
----> 1 client.connect(hostname=target, username=username, password=password)

~/.local/lib/python3.9/site-packages/paramiko/client.py 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, disabled_algorithms)
    433             key_filenames = key_filename
    434
--> 435         self._auth(
    436             username,
    437             password,

~/.local/lib/python3.9/site-packages/paramiko/client.py in _auth(self, username, password, pkey, key_filenames, allow_agent, look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host, passphrase)
    762         # if we got an auth-failed exception earlier, re-raise it
    763         if saved_exception is not None:
--> 764             raise saved_exception
    765         raise SSHException("No authentication methods available")
    766

~/.local/lib/python3.9/site-packages/paramiko/client.py in _auth(self, username, password, pkey, key_filenames, allow_agent, look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host, passphrase)
    749         if password is not None:
    750             try:
--> 751                 self._transport.auth_password(username, password)
    752                 return
    753             except SSHException as e:

~/.local/lib/python3.9/site-packages/paramiko/transport.py in auth_password(self, username, password, event, fallback)
   1507             return []
   1508         try:
-> 1509             return self.auth_handler.wait_for_response(my_event)
   1510         except BadAuthenticationType as e:
   1511             # if password auth isn't allowed, but keyboard-interactive *is*,

~/.local/lib/python3.9/site-packages/paramiko/auth_handler.py in wait_for_response(self, event)
    234                 if (e is None) or issubclass(e.__class__, EOFError):
    235                     e = AuthenticationException("Authentication failed.")
--> 236                 raise e
    237             if event.is_set():
    238                 break

AuthenticationException: Authentication failed.

In [96]:
Thanks in advance!
-v
 
Clément
just joined
Posts: 5
Joined: Wed Sep 29, 2021 2:19 pm

Re: Connection via Paramiko failing but works fine with SSH login from CLI

Mon May 02, 2022 7:46 pm

Hi,
Cause I saw your post and I get the same problem.
I solve it by using the parameter from paramiko.SSHClient(look_for_keys=False).

It looks likes Mikrotik devices block the connection waiting to yes or no you are using a private keys for your ssh session.

Something like :
ssh.connect(hostname="x.x.x.x", port=xxxx, username="x", password="x", look_for_keys=False)
Works as well for me.

Regards,
Clément.

Who is online

Users browsing this forum: abbio90 and 18 guests