bash - 在 bash 脚本中向 git 提供密码

标签 bash git shell passphrase

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

最佳答案

我尝试了 ssh-agent 和 SSH_ASKPASS 的解决方案,但没有任何效果,然后我找到了使用 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

关于bash - 在 bash 脚本中向 git 提供密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34155308/

相关文章:

bash - 替换分号后的字符串

Git:如何使用开发中所做的更改来更新本地功能分支?

bash - 为什么一定要逃走 |和 + 在撇号之间的 grep?

linux - 如何限制从 grep 返回的结果数?

bash - 连接和追加的区别

git - 我可以使用 .gitignore_global 忽略多个存储库中所有用户的文件吗?

angular - 忽略 .gitignore 中名为 npm-debug.log.XXXXXX 的文件

linux - 如何使用 sed 从长字符串中提取键的值?

bash - 如何将 Bash 命令的输出分配给变量?

linux - mkdir 中的详细选项是什么?