如何在不重新输入 SSH 密码的情况下执行“ git pull”?

是否可以配置 git/ssh,这样我就不必在每次执行 git pull时输入密码?注意,回购是 github 上的私有回购。

或者,从私有的 Github 回购中自动部署代码的最佳实践是什么?

其他详细信息: 基于 Fedora 运行公共 AMI 的 EC2实例。

113906 次浏览

Have a look at this link 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.

Your situation is now fixed, however for me it was the fact that I had more than one key in ~/.ssh/

To resolve the problem I had to create a file called ~/.ssh/config and add the line:

IdentityFile ~/.ssh/my_key2_rsa

where ~/.ssh/my_key2_rsa is my key.

I enabled the password caching as described here:

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'

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)

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.

The source of the solution is https://askubuntu.com/questions/362280/enter-ssh-passphrase-once/853578#853578

Try this:

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.

I updated my ~/.ssh/config file to read the following, and no longer have to enter my ssh password.

Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_ed25519

open (or create) the ~/.ssh/config file and add these lines to the file:

Host *
UseKeychain yes

Source: https://support.atlassian.com/bitbucket-cloud/docs/set-up-an-ssh-key/