在SSH中使用bash脚本时,为Git输入私钥密码

时间:2018-03-06 16:54:04

标签: bash git ssh

这是我到目前为止在<<EOF中的代码,同时ssh为一个框

mkdir ~/.ssh/
rm ~/.ssh/config
touch ~/.ssh/config
echo 'Host *******' >> ~/.ssh/config
echo '   StrictHostKeyChecking no' >> ~/.ssh/config

cp ~/gittoken ~/.ssh/id_rsa
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa

cd /root
git clone ***********
expect "assword:"
send "$git_token_passphrase\r";
interact

我得到的错误是

Permission denied (publickey).
fatal: Could not read from remote repository.

我把我见过的多个不同的答案结合起来,我觉得这可能对我的情况有帮助。

当我在盒子上手动运行它时,我可以运行所有这些命令。所以我的猜测是,在通过脚本进行ssh时运行它们需要一些额外的步骤。此外,期待和发送不能在我的系统上工作,但我想我还是把它们放在那里,以表明我已经尝试过了。

/bin/bash: line 105: expect: command not found
/bin/bash: line 106: send: command not found
/bin/bash: line 107: interact: command not found

1 个答案:

答案 0 :(得分:0)

您可以使用sshpass来实现此目标。

但是因为现在整个设置的安全性不在于 谁知道密码,但只有那么强 脚本中的安全性或 - 如果你有点 对于一些持有密码的文件,你可能不那么松懈 通过运行

删除SSH密钥的密码保护
ssh-key -f ~/.ssh/id_rsa -p

并输入两次空密码。

相关问题