[Python] Not a valid OPENSSH private key file - Paramiko

Discussão em 'Python' iniciado por Stack, Março 7, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to connect to a host using paramiko. I'm able to successfully connect to the host through winscp using the private key, but the script fails with below error

    raise SSHException("not a valid {} private key file".format(tag)) paramiko.ssh_exception.SSHException: not a valid OPENSSH private key file

    import paramiko
    ssh = paramiko.SSHClient()

    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

    ssh.connect('hostname.com', username='user', key_filename='private.ppk')

    stdin, stdout, stderr = ssh.exec_command('ls')
    print(stdout.readlines())
    ssh.close()

    Any suggestion would be appretiated,

    Continue reading...

Compartilhe esta Página