0

I'm trying to connect to a Linux server using Python's paramiko library. I've generated public-private key pair using PuTTYGEN (type of the key - in the Key dropdown list - 'SSH-2 RSA Key'; in the Parameters field - 'RSA'). I added the output of the public key in the ~/.ssh/authorized_keys2. In order to connect to the server I need to decrypt the private key (private_key.ppk) with the password in the PAGEANT.

When logging manually (start Putty, double click on the saved connection) everything works well - I get connected to the server without using my password.

My Python code:

import paramiko
import os
from credentials import * # password file

private_key = "path\\to\\the\\private\\key.ppk"
k = paramiko.RSAKey.from_private_key_file(private_key, password=password)
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(hostname = 'server_ip_address', port=port, username = username, pkey=k)

I get the following error:

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

I suspect that .ppk extension might not be handled by paramiko.

balkon16
  • 1,338
  • 4
  • 20
  • 40

0 Answers0