从私有 Git 存储库推送/拉取的 Bash 脚本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10421430/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bash Script to Push/Pull from Private Git Repository?
提问by Peter
I'm trying to find a way that I can write a bash script that will auto-pull from our Private Github Repository every midnight and update our development site.
我试图找到一种方法来编写一个 bash 脚本,该脚本将在每半夜从我们的私有 Github 存储库中自动拉取并更新我们的开发站点。
Our repo is private for obvious reasons and anything close that I've found always asks for the passphrase. Our server has it's own Github Account that it uses to push and pull from the repository but I just don't know how to do that automatically.
由于显而易见的原因,我们的回购是私有的,我发现的任何接近的东西总是要求输入密码。我们的服务器有自己的 Github 帐户,用于从存储库中推送和拉取,但我不知道如何自动执行此操作。
Can anyone point me in the right direction?
任何人都可以指出我正确的方向吗?
回答by djs
In order to automate your push/pull, you'll need to set up passwordless authentication. To do so, you use ssh (instead of https). If you haven't used ssh with github, or at all, before, then you'll need to perform a few steps to get things configured.
为了自动执行推/拉,您需要设置无密码身份验证。为此,您使用 ssh(而不是 https)。如果您之前没有在 github 上使用过 ssh,或者根本没有使用过,那么您需要执行一些步骤来进行配置。
On your machine, generate an ssh key:
在您的机器上,生成一个 ssh 密钥:
$ ssh-keygen -t rsa
Make sure you leave the passphrase field blank. This leaves the local private key unencrypted, but no less secure for the actual communication over the internet.
确保将密码字段留空。这使得本地私钥未加密,但对于通过 Internet 进行的实际通信而言同样安全。
Then, upload ~/.ssh/id_rsa.pubto github under Account Settings | SSH Keys
然后,~/.ssh/id_rsa.pub在帐户设置下上传到github | SSH 密钥
Now you should be able to push and pull from that machine without a password. Try it out:
现在您应该能够在没有密码的情况下从那台机器上推拉。试试看:
git clone [email protected]:user/repo.git
You can then put these commands in your bash script as appropriate. If you need to do this for multiple machines, you'll need to upload each key, or copy the private key (~/.ssh/id_rsa) to each one.
然后,您可以根据需要将这些命令放入 bash 脚本中。如果您需要为多台机器执行此操作,则需要上传每个密钥,或将私钥 ( ~/.ssh/id_rsa)复制到每个机器上。
See github helpfor more info. Also take a look at the deploy keyspage, as that may provide better granularity of security for your situation.

