0

I'm trying to read a text file from a server using ssh from python 3.5. I'm using paramiko to connect to the server but unfortunately, I'm having trouble actually connecting to the server.

this is the code I'm using to connect to the server

import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('IP ADDRESS OF THE SERVER', key_filename="/home/user/.ssh/id_ecdsa" ,look_for_keys=True)

but every time I try to connect to the server I'm getting an authentication failed error message, can anyone see what I'm doing wrong here? Any advice would be appreciated

This is the error I'm getting everytime i connect.

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/site-packages/paramiko/client.py", line 380,    in connect
look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host)
File "/usr/local/lib/python3.5/site-packages/paramiko/client.py", line 603, in _auth
raise saved_exception
File "/usr/local/lib/python3.5/site-packages/paramiko/client.py", line 580, in _auth
allowed_types = set(self._transport.auth_publickey(username, key))
File "/usr/local/lib/python3.5/site-packages/paramiko/transport.py", line 1331, in auth_publickey
return self.auth_handler.wait_for_response(my_event)
File "/usr/local/lib/python3.5/site-packages/paramiko/auth_handler.py", line 208, in wait_for_response
raise e
paramiko.ssh_exception.AuthenticationException: Authentication failed.
1
  • Can we see the error message? Commented Oct 11, 2016 at 11:21

2 Answers 2

2

You should use your private key to connect to a remote server. Your public key must be already installed in the server side, i.e. it must be listed in ~/.ssh/authorized_keys.

Try first from the command line, and only then use Python/paramiko. Check the permissions of the files/directories if all that fails.

Sign up to request clarification or add additional context in comments.

1 Comment

hey thanks for the reply, I have added the public key to the authorized keys on the server, and can connect just fine from command line. I have checked the permission and owners of the files, and the folder that they reside in and everything is correct. I changed the key_filename to point to my private key but again I keep getting the authentication failed error message.
0

Turns out I simply just forgot to add in the username in the connection string. works perfectly now.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.