简体   繁体   English

在 SSH'ing bash 脚本中输入 Git 的私钥密码

[英]Enter Private Key Passphrase for Git in While SSH'ing bash script

Here's the code I have so far in an <<EOF while ssh'ing into a box这是我到目前为止在<<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

The error I'm getting is我得到的错误是

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

I've sort of combined multiple different answers I've seen on SO that I thought might help my case.我已经将我在 SO 上看到的多个不同答案组合在一起,我认为这可能对我的案子有所帮助。

I can run all these commands when I'm manually running them on the box.当我在盒子上手动运行它们时,我可以运行所有这些命令。 So my guess is that running them while ssh'ed through a script requires some extra step.所以我的猜测是在通过脚本 ssh 时运行它们需要一些额外的步骤。 Also, expect and send don't work on my system, but I figured I'd put them there anyway to show I'd tried them.此外,expect 和 send 在我的系统上不起作用,但我想无论如何我都会把它们放在那里以表明我已经尝试过它们。

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

You may use sshpass to achieve this.您可以使用sshpass来实现这一点。

But since now the security of the whole setup rests not in the head of whoever knows the password but is only as strong as the security in the script or—if you're a bit less slack—into some file holding the password, you might as well just remove password protection from your SSH key by running但是,由于现在整个设置的安全性不在知道密码的人的头脑中,而是与脚本中的安全性一样强,或者——如果你不那么懈怠——到一些保存密码的文件中,你可能也可以通过运行从 SSH 密钥中删除密码保护

ssh-keygen -f ~/.ssh/id_rsa -p

and entering an empty password twice.并输入两次空密码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM