Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSHTunnel with key value (not path)

I have an SSH key stored in a variable as I'm using a cloud function and don't have access to a filesystem. For example:

with SSHTunnelForwarder(
   ssh_address_or_host='my-host', 
   ssh_username='my-user',
   ssh_pkey='/home/david/.ssh/id_rsa' # this
) as tunnel:

Instead of passing the path to the ssh_pkey file, how can I hardcode that as a string? Yes, I will move it to an environmental variable or something else, but for testing, is there a way to pass it a string?

like image 235
David542 Avatar asked Dec 19 '25 10:12

David542


1 Answers

As @TimRoberts commented, the ssh_pkey accepts paramiko.pkey.PKey instance, not only a path to a key file.

For an example how to construct PKey from a string, see:
SSH/SCP through Paramiko with key in string

like image 73
Martin Prikryl Avatar answered Dec 21 '25 00:12

Martin Prikryl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!