Embedding public key as string in Paramiko Application

那年仲夏 提交于 2020-01-13 10:19:11

问题


I'm trying to create a single file executable in python and using paramiko for my SSH. I need to eliminate external files such as public key files and try to go for embedded strings.

I tried this solution but it's not working for me..

How do I accomplish this? Thanks.


回答1:


The solution you mentioned:

key = paramiko.RSAKey(data=base64.b64decode('AAblablabla...'))

works fine however it may be inconvenient to store the key in base64 format.

The following code shows how to use the key stored in "plain-text" format (as key-files in ~/.ssh directory):

import paramiko
import StringIO

my_key = """\
-----BEGIN RSA PRIVATE KEY-----
<your key here>
-----END RSA PRIVATE KEY-----"""

pkey = paramiko.RSAKey.from_private_key(StringIO.StringIO(my_key))

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname='host', username='user', pkey=pkey)

...

ssh.close()


来源:https://stackoverflow.com/questions/27669813/embedding-public-key-as-string-in-paramiko-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!