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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With