在bash脚本中为git提供密码

时间:2015-12-08 11:58:04

标签: bash git shell passphrase

如何在bash脚本中使用git fetch / pull提供密码短语。 我真的需要在bash脚本中执行它,而不使用ssh-add或类似的东西。 有可能吗?

1 个答案:

答案 0 :(得分:3)

我使用SSH_ASKPASS尝试了ssh-agent和解决方案,但没有任何效果,然后我找到了使用http://expect.sourceforge.net/的解决方案

示例(在shell中执行):

pass="passwod"
/usr/bin/expect <<EOD
spawn git fetch origin $BRANCH
expect "Enter passphrase for key '/home/$USERNAME/.ssh/id_rsa': "
send "$pass\r"
expect eof
EOD