【问题标题】:git push using crontab every hour prompting passwordgit push 使用 crontab 每小时提示密码
【发布时间】:2019-05-09 10:22:19
【问题描述】:

我创建了一个 shell 脚本文件,用于每小时使用 crontab 自动推送一个 git 存储库,如下所示,

backup.sh

cd /home/user/share/my_project && git commit -a -m "hourli crontab backup 'date'"
cd /home/user/share/my_project && git push origin branch1
send mypassword\r
wait

这段代码的问题是,git 使用 ssh 并且每次我们使用bash ./backup.sh 运行这段代码时都会在终端中询问密码。不接受在 shell 脚本中指定的密码。

【问题讨论】:

  • 您可能需要使用身份验证令牌或类似的东西吗?
  • 存储库位于隔离的本地网络中,但“发送 mypassword\r”不起作用
  • 只是好奇,为什么每个小时都在推,没有变化? .你为什么要采用这种方法而不是 Jenkins 或 CI 方式?
  • @Akshaybarahate 我们在一台本地服务器上托管了一个应用程序,很少有开发人员同时直接在同一服务器上工作。不幸的是,由于某些原因,我们不必为本地项目创建副本。所以我们尝试使用 crontab 每小时推送一次代码。让开发者不用担心代码备份和 git 的问题。
  • @Shijin 这听起来很容易让自己陷入困境......

标签: linux git shell


【解决方案1】:

我同意 cmets 的观点,即这不是最佳做法。

忽略这一点并继续进行黑客攻击,您应该查看git-credential-store。文档中的示例;

$ git config credential.helper store
$ git push http://example.com/repo.git
Username: <type your username>
Password: <type your password>

[several days later]
$ git push http://example.com/repo.git
[your credentials are used automatically]

凭据将存储在本地,在~/.git-credentials 中未加密。如果这是一个可以接受的权衡,那么它会为你工作。只需确保您了解运行 cron 作业的用户上下文即可。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-24
    • 2021-01-27
    • 2020-09-08
    • 2018-07-18
    • 2023-02-16
    • 2014-04-02
    相关资源
    最近更新 更多