Paramiko — using encrypted private key file on OS X

前端 未结 3 609
天命终不由人
天命终不由人 2021-02-07 05:10

I\'m trying to use Paramiko to connect to an SSH server from Python. This is what I tried so far:

>>> import paramiko
>>> import os
>>>         


        
3条回答
  •  北恋
    北恋 (楼主)
    2021-02-07 05:26

    The RSAKey.from_private_key_file() is inherited from PKey(); an optional parameter of this method is a password. To quote:

    If the private key is encrypted and password is not None, the given password will be used to decrypt the key (otherwise PasswordRequiredException is thrown).

    As you're not passing a password and your key is encrypted this exception will always be thrown. There's only one way round this problem, to actually give the method a password. You, therefore, need a way of getting the password out of the OSXKeychain.

    You could use the cross-platform Keyring module to do this.

提交回复
热议问题