110

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.

Or, alternatively, what would be the best practice to automate code deployment from a private Github repo?

Additional details: EC2 instance running a public AMI based on Fedora.

Cœur
  • 37,241
  • 25
  • 195
  • 267
jldupont
  • 93,734
  • 56
  • 203
  • 318

7 Answers7

78

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.

Lernkurve
  • 20,203
  • 28
  • 86
  • 118
Fredrik Pihl
  • 44,604
  • 7
  • 83
  • 130
  • 3
    This link was helpful in explaining what commands to run in order to get your passphrase saved in `ssh-agent`: http://rabexc.org/posts/using-ssh-agent – Mateus Gondim Oct 11 '17 at 15:36
  • I dont want use keys. Simple i have user\pass and i want save it on git client side – nim Jan 11 '19 at 19:20
  • Why does the link only provide Mac/Widows options? I want to git pull on the unix server without reentering the pass. managed to make it work for a historic project but cant tell what I did there. Is the point that when you ssh to a remote unix machine the key is passed on and that is used as a git pull (or private composer vcs) key instead? I believe I'm misunderstanding something here. Any help appreciated :) – trainoasis Aug 07 '19 at 08:26
45

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'
tuananh
  • 747
  • 8
  • 17
Sileria
  • 15,223
  • 4
  • 49
  • 28
  • 1
    Thanks, temuri- I've been looking everywhere for this exact detail. It wasn't working, but the documentation seemingly doesn't mention it is only for HTTPS. – Mike Emery Jul 06 '15 at 16:25
  • 2
    If you use a password (**not** a passphrase with key file) for an SSH-based URL of a remote Git repo, you cannot save the password at all. But I noticed that after issuing any git command, you can **immediately type the password and press Enter**. You don't need to wait for the password prompt to appear. – ADTC Nov 18 '15 at 04:18
  • 2
    git still ask pass – nim Jan 11 '19 at 19:03
18

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.

Shailesh
  • 2,116
  • 4
  • 28
  • 48
12

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

infoclogged
  • 3,641
  • 5
  • 32
  • 53
6

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.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
  • 1
    Thanks for this, my `id_rsa` and `id_rsa.pub` files have a custom name which is why git would never recognize it. ref: https://linux.die.net/man/5/ssh_config – lasec0203 Aug 16 '17 at 02:58
2

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
The Camster
  • 1,850
  • 1
  • 20
  • 27
2

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/

Shah
  • 2,126
  • 1
  • 16
  • 21