如何使从文件的ssh-添加读取密码? [英] How to make ssh-add read passphrase from a file?
问题描述
我想在的ssh-agent添加关键
,并希望 SSH-添加
使用从文件中读取密码。如何其可能的?
I am trying to add key in ssh-agent
and want ssh-add
read password from the file using. How its possible?
我怎么这个过程从shell脚本自动化?
How do I automate this process from the shell script?
推荐答案
根据您的分布和版本SSH-添加您可能能够或不使用 -p
SSH-ADD的选项,以这种方式从标准输入读取密码:
Depending on your distribution and on the version of ssh-add you may be able or not to use the -p
option of ssh-add that reads the passphrase from stdin in this way:
cat passfile | ssh-add -p keyfile
如果这不是工作,就可以使用期待,一个Unix工具使交互式应用非交互式。你必须从你的包管理器进行安装。
If this is not working you can use Expect, a Unix tool to make interactive applications non-interactive. You'll have to install it from your package manager.
在期待我写你的工具。在一个名为文件的 SSH-添加通的内容只需复制并在其上设置可执行权限(搭配chmod + X SSH-添加通
)。你也可以把它复制到/ usr / bin中或/ usr / local / bin目录是从$ PATH搜索访问。
I have written a tool for you in expect. Just copy the content in a file named ssh-add-pass and set executable permissions on it (chmod +x ssh-add-pass
). You can also copy it to /usr/bin or /usr/local/bin to be accessible from the $PATH search.
#!/bin/bash
if [ $# -ne 2 ] ; then
echo "Usage: ssh-add-pass keyfile passfile"
exit 1
fi
eval $(ssh-agent)
pass=$(cat $2)
expect << EOF
spawn ssh-add $1
expect "Enter passphrase"
send "$pass\r"
expect eof
EOF
用法很简单: SSH-加通密钥文件密码文件
这篇关于如何使从文件的ssh-添加读取密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!