pysftp AuthenticationException while connecting to server with private key
I could finally connect.
Converted the file to a .pem
file using PuTTY. Passed this .pem
file and kept the rest of the parameters the same as before.
pysftp.Connection(host='hostname', username='username',
password='password', private_key='path to .pem file')
Hope this helps someone having similar issues.
heathensoul
Updated on July 25, 2022Comments
-
heathensoul almost 2 years
I am trying to connect to SFTP server. I have a private key along with a password. I have tried to read related questions on SO, but have been unable to successfully connect.
This is what I have tried:
pysftp.Connection(host=<hostname>, username=<username>, password=<password>, private_key=<path to .ppk file>)
AuthenticationException: Authentication failed
pysftp.Connection(host=<hostname>, username=<username>, private_key_pass=<password>, private_key=<path to .ppk file>)
SSHException: not a valid DSA private key file
However, I can use the same credentials and connect with FileZilla. FileZilla asked for password and converted the
.ppk
file into an unprotected file.I tried to use the same host name, username and key file as used in FileZilla, but I continue getting errors. Also tried connecting using Paramiko.
-
kidbrax about 8 yearsSo you still have to use the password parameter even though you are using the PEM key? I am currently having the same issue.
-
Sergey Makhonin over 4 yearsHere is a decent instruction for converting .ppk to .pem and vice versa: aws.amazon.com/premiumsupport/knowledge-center/…
-
General4077 over 4 yearsAs Martin Prikryl pointed out you can't use password with private_key. This likely should be
private_key_pass=<password>
as in the original code example -
Martin Prikryl over 4 yearsWithout more information, this is a mere comment to @heathensoul answer, rather than a standalone answer.
-
Martin Prikryl over 4 yearsI do not see how does this answer the question. You have shown how to generate a new key. The question about problems with using an existing key.
-
user3632065 over 4 yearsIn my case problem was with my private key, the how I was generating that key was not support by pysftp and I was able to solve with new key that I have generated in this way.
-
Martin Prikryl over 4 yearsBut you cannot just generate a new key. You have to put its public key on the server, what your answer does not even mention. And why doing it this way, if you can simply convert the existing key to the format that pysftp supports.
-
Nicholas Flees over 3 yearsIt would be helpful to know why you needed to downgrade in order to solve the issue.
-
BCArg about 3 yearsI wanted to try that, though that version of pysftp is only compatible with
python[version='2.7.*|3.4.*|3.5.*']