Paramiko: "not a valid DSA private key file"
Asked Answered
S

1

1

I am trying to connect to some SFTP using a private key file that looks like:

---- BEGIN SSH2 ENCRYPTED PRIVATE KEY ----
Subject: L0709146
Comment: "1024-bit dsa, L0709146@pxz102, Wed Jan 12 2022 11:25:54 +010\
0"
P2/bla...bla...bla
---- END SSH2 ENCRYPTED PRIVATE KEY ----

Using the following code:

import paramiko
path = "path/to/my/file"

transport = paramiko.Transport((self.host, self.port))
transport.connect(username=self.user,pkey=paramiko.DSSKey.from_private_key(open(path)))
# ^^^ Error line ^^^

#transport.connect(username=self.user,pkey=paramiko.RSAKey.from_private_key(open(path)))
#transport.connect(username=self.user,pkey=paramiko.ECDSAKey.from_private_key(open(path)))
sftp = paramiko.SFTPClient.from_transport(transport)
logging.info(sftp.listdir())

I'm not sure but I understand that is a DSA private key file, but I obtained the error:

paramiko.ssh_exception.SSHException: not a valid DSA private key file

I tried with other options but, a similar error

paramiko.ssh_exception.SSHException: not a valid RSA private key file
paramiko.ssh_exception.SSHException: not a valid EC private key file
paramiko.ssh_exception.SSHException: not a valid OPENSSH private key file

I used the FileZilla client, I hadn't problem connecting to the SFTP, I don't get why with Python I have problems.

Squireen answered 21/1, 2022 at 12:6 Comment(0)
E
1

You have a private key in rarely used ssh.com format. Paramiko does not support it. You have to convert it to the OpenSSH format.

You can use ssh-keygen like this:

ssh-keygen -i -f sshcomkey > opensshkey

On Windows you can also use PuTTYgen.

Related question: Paramiko: "not a valid RSA private key file"

Europa answered 21/1, 2022 at 12:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.