My Python is connecting to a remote server via SSH as follows
import paramiko client = paramiko.SSHClient() client.load_system_host_keys() client.connect(hostname=hostname, username=username)
and it receives an error
paramiko.ssh_exception.AuthenticationException: Authentication failed.
Full error trace is
Traceback (most recent call last):
File "main.py", line 26, in <module>
client.connect(hostname=hostname, username=username)
File "/usr/lib/python3/dist-packages/paramiko/client.py", line 435, in connect
self._auth(
File "/usr/lib/python3/dist-packages/paramiko/client.py", line 764, in _auth
raise saved_exception
File "/usr/lib/python3/dist-packages/paramiko/client.py", line 740, in _auth
self._transport.auth_publickey(username, key)
File "/usr/lib/python3/dist-packages/paramiko/transport.py", line 1605, in auth_publickey
return self.auth_handler.wait_for_response(my_event)
File "/usr/lib/python3/dist-packages/paramiko/auth_handler.py", line 250, in wait_for_response
raise e
paramiko.ssh_exception.AuthenticationException: Authentication failed.
How can I fix this error?
This error is usually due to deprecated version of paramiko.
First, check your paramiko version:
pip show paramiko
if the version is older than 2.9.0, then upgrade your paramiko as follows
pip install --upgrade paramiko