在SSH中将私钥指定为字符串 [英] Specify private key in SSH as string

查看:165
本文介绍了在SSH中将私钥指定为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用-i选项通过SSH通过SSH连接到服务器,以指定私钥:

I can connect to a server via SSH using the -i option to specify the private key:

ssh -i ~/.ssh/id_dsa user@hostname

我正在创建一个脚本,该脚本从数据库中获取id_dsa文本,但是我不确定如何将该字符串提供给SSH.我需要类似的东西:

I am creating a script that takes the id_dsa text from the database but I am not sure how I can give that string to SSH. I would need something like:

ssh --option $STRING user@hostname

其中$STRING包含id_dsa的值.我需要知道--option是否存在.

Where $STRING contains the value of id_dsa. I need to know the --option if there is one.

推荐答案

没有这样的开关-因为它会泄漏敏感信息.如果有的话,任何人都可以通过执行一个简单的ps命令来获取您的私有密钥.

There is no such switch - as it would leak sensitive information. If there were, anyone could get your private key by doing a simple ps command.

编辑 :(由于在评论中添加了详细信息)

EDIT: (because of theg added details in comment)

您确实应该将密钥存储在一个临时文件中.如果不使用mktemp之类的命令来创建临时文件,请确保在写入文件之前正确设置了权限.

You really should store the key in to a temporary file. Make sure you set the permissions correctly before writing to the file, if you do not use command like mktemp to create the temporary file.

<罢工> 确保您运行代理(如果是OpenSSH,则为代理)进程,并使用<whatever command you use to fetch it form the database> | ssh-add -加载密钥.

Make sure you run the broker (or agent in case of OpenSSH) process and load the key using <whatever command you use to fetch it form the database> | ssh-add -

这篇关于在SSH中将私钥指定为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆