bash 执行 ssh-add 并自动输入密码的脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13548076/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 03:51:04  来源:igfitidea点击:

Script that executes ssh-add and feeds the passphrase automatically

gitbashssh

提问by Sotirios Delimanolis

I'm using a script that executes

我正在使用执行的脚本

eval `ssh-agent`
ssh-add

which prompts you to input your SSH passphrase. Is it possible to input the passphrase from the script? The goal of this is to open connection to git repo whenever I open GitBash without having to constantly input my passphrase. I know putting passphrase in a script is terrible security, but I really don't care. I'm doing for testing.

这会提示您输入 SSH 密码。是否可以从脚本中输入密码?这样做的目的是在我打开 GitBash 时打开与 git repo 的连接,而无需不断输入我的密码。我知道将密码短语放在脚本中是很糟糕的安全性,但我真的不在乎。我正在做测试。

采纳答案by qqx

If you're going to do that you'd be better off just not using a passphrase on the key. In which case you wouldn't even need to use ssh-agent. You can change or remove a passphrase from an existing key with ssh-keygen -p.

如果您打算这样做,最好不要在密钥上使用密码。在这种情况下,您甚至不需要使用ssh-agent. 您可以使用 更改或删除现有密钥中的密码短语ssh-keygen -p

回答by axel22

Answer how to do it is here:

回答如何做在这里:

https://ifireball.wordpress.com/2015/01/12/automatic-loading-of-ssh-keys-from-scripts/

https://ifireball.wordpress.com/2015/01/12/automatic-loading-of-ssh-keys-from-scripts/

Summary:

概括:

echo "exec cat" > ap-cat.sh
chmod a+x ap-cat.sh
export DISPLAY=1
echo $MY_SSH_PASS | SSH_ASKPASS=./ap-cat.sh ssh-add ~/.ssh/id_rsa
rm ap-cat.sh

Note:you need to export the DISPLAYenvironment variable to some value.

注意:您需要将DISPLAY环境变量导出为某个值。