How to connect to SFTP via Paramiko with SSH key - Pageant

I am trying to connect to SFTP via Paramiko with an SSH key protected by a passphrase. I uploaded the key to Pageant (which, as I understand it, is supported by Paramiko), but I can not get it to decrypt my private key.

I found this example here that references allow_agent=True , but this is not a parameter that can be used with SFTPClient .

Can anyone advise if it is possible to work with Paramiko and Pageant in this way?

This is my code at the moment that raises a PasswordRequiredException

 privatekeyfile = 'path to key' mykey = paramiko.RSAKey.from_private_key_file(privatekeyfile) transport = paramiko.Transport(('host', 'port')) transport.connect('username',pkey = mykey) sftp = paramiko.SFTPClient.from_transport(transport) 
+5
source share
1 answer

When downloading an encrypted key using from_private_key_file you must specify a passphrase.

Note that you do not need to download the key at all when using Pageant. This is the point of use of the authentication agent. But only the SSHClient class supports the Pageant object. The Transport class itself does not work.

You must follow the code in How to use Pageant with Paramiko on Windows?

After connecting and authenticating, use the SSHClient.open_sftp method to get your SFTPClient instance.

Also note that allow_agent is True by default.

+4
source

Source: https://habr.com/ru/post/1200729/


All Articles