如何在不重新输入 SSH 密码的情况下执行 `git pull`?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6265595/
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
How can I perform a `git pull` without re-entering my SSH password?
提问by jldupont
Is it possible to configure git/ssh
so I don't have to enter my passphrase every time I want to perform a git pull
? Note that the repo is a private one on github.
是否可以进行配置,git/ssh
这样我就不必每次要执行密码时都输入密码git pull
?请注意,该存储库是 github 上的私有存储库。
Or, alternatively, what would be the best practice to automate code deployment from a private Github repo?
或者,从私有 Github 存储库自动部署代码的最佳实践是什么?
Additional details:EC2 instance running a public AMI based on Fedora.
其他详细信息:运行基于 Fedora 的公共 AMI 的 EC2 实例。
采纳答案by Fredrik Pihl
Have a look at this link https://help.github.com/articles/working-with-ssh-key-passphrases/
看看这个链接https://help.github.com/articles/working-with-ssh-key-passphrases/
But I don't want to enter a long passphrase every time I use the key!
Neither do I! Thankfully, there's a nifty little tool called
ssh-agent
that can save your passphrase securely so you don't have to re-enter it. If you're on OSX Leopard or later your keys can be saved in the system's keychain to make your life even easier. Most linux installations will automatically start ssh-agent for you when you log in.
但是我不想每次使用密钥时都输入很长的密码!
我也不!值得庆幸的是,有一个漂亮的小工具
ssh-agent
可以安全地保存您的密码,这样您就不必重新输入它。如果您使用的是 OSX Leopard 或更高版本,您的钥匙可以保存在系统的钥匙串中,让您的生活更加轻松。大多数 linux 安装会在您登录时自动为您启动 ssh-agent。
回答by Fredrik Pihl
Your situation is now fixed, however for me it was the fact that I had more than one key in ~/.ssh/
你的情况现在已经解决了,但对我来说,事实上我有不止一个钥匙 ~/.ssh/
To resolve the problem I had to create a file called ~/.ssh/config
and add the line:
为了解决这个问题,我必须创建一个名为的文件~/.ssh/config
并添加以下行:
IdentityFile ~/.ssh/my_key2_rsa
where ~/.ssh/my_key2_rsa
is my key.
~/.ssh/my_key2_rsa
我的钥匙在哪里。
回答by Sileria
I enabled the password caching as described here:
我启用了密码缓存,如下所述:
https://help.github.com/articles/caching-your-github-password-in-git/#platform-linux
https://help.github.com/articles/caching-your-github-password-in-git/#platform-linux
To cache the password for a month:
将密码缓存一个月:
git config --global credential.helper 'cache --timeout=2628000'
回答by infoclogged
I dont know why hasnt anyone reported this yet. But the simplest approach would be to simply add a single line AddKeysToAgent yes
on the top of the .ssh/config file. Ofcourse ssh-agent
must be running beforehand. If its not running ( check by the command ssh-agent
on the terminal ) , then simply run it eval $(ssh-agent)
我不知道为什么还没有人报告这个。但最简单的方法是AddKeysToAgent yes
在 .ssh/config 文件的顶部添加一行。当然ssh-agent
必须事先运行。如果它没有运行(通过ssh-agent
终端上的命令检查),那么只需运行它eval $(ssh-agent)
I can confirm that this works, because in my project with lots of submodules and for each submodule being cloned, I had to type in my ssh passphrase. After the above trick, I dont need to do it anymore.
我可以确认这是有效的,因为在我的项目中有很多子模块并且对于每个被克隆的子模块,我必须输入我的 ssh 密码。在上面的技巧之后,我不需要再这样做了。
The source of the solution is https://askubuntu.com/questions/362280/enter-ssh-passphrase-once/853578#853578
解决方案的来源是https://askubuntu.com/questions/362280/enter-ssh-passphrase-once/853578#853578
回答by Yankee
Try this:
尝试这个:
git config credential.helper store
git config credential.helper store
You'll have to enter your password once, after that it is stored in a folder inside root.
您必须输入一次密码,然后将其存储在根目录中的文件夹中。
As comments pointed out, This does NOT work for SSH passwords, only for HTTPS passwords.
正如评论指出的那样,这不适用于 SSH 密码,仅适用于 HTTPS 密码。