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?
Code: Select all
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]:
-v