0

I'm trying to by pass the password prompt every time I run git pull.

I'm running on Ubuntu. This is my Git config:

git config --list
user.name=Benlong Heng
user.email=benlongheng@outlook.com
credential.helper=cache --timeout=3600
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=git@bitbucket.org:benlongheng/benlong-web-app.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
credential.helper=store

I've been following this answer, and for some reason, I still keep getting the prompt after running git pull:

$ git pull
Enter passphrase for key '/root/.ssh/id_rsa':

Am I missing something? Any hints?

Scott Weldon
  • 9,673
  • 6
  • 48
  • 67
code-8
  • 54,650
  • 106
  • 352
  • 604
  • 1
    Are you doing development as root? You really should not be. – Andy Lester Oct 03 '16 at 22:23
  • No, I was just trying to pull as root. I developed locally on my Mac. I'm new to Linux stuffs. – code-8 Oct 03 '16 at 22:24
  • 2
    You protected your key with a passphrase. Lookg into ssh-agent. http://askubuntu.com/questions/362280/enter-ssh-passphrase-once – k0pernikus Oct 03 '16 at 22:26
  • 3
    @ihue Don't do anything as root that you don't need to do as root. If you do need to do something that requires root, use sudo. You should not have to do anything involving git that requires you to use root. – Andy Lester Oct 03 '16 at 22:28
  • 1
    Basically, I think you confuse the protection of the pubkey with the login credentials of github. These are not related. (And since you run it with `sudo` git looks for `/root/.ssh/id_rsa` to find the key.) Did you even create of set of keys to use for github? – k0pernikus Oct 03 '16 at 22:32
  • See this for further reference: https://help.github.com/articles/generating-an-ssh-key/ – k0pernikus Oct 03 '16 at 22:33

1 Answers1

4

The answer you linked to is for HTTPS remotes, but this line in your config:

remote.origin.url=git@bitbucket.org:username/repo.git

indicates you are connecting via SSH. The fact that you are being prompted for a password means that you have password-protected your SSH key. To cache your password for the current session, do:

eval $(ssh-agent)
ssh-add

You'll be prompted for your password once, and after that it will be cached.

If you don't want to be prompted for a password ever, then you'll need to generate a new key with no passphrase. I recommend against this, since anyone who gets ahold of that key file can impersonate you anywhere that you use the key.


Also, I noticed this:

Enter passphrase for key '/root/.ssh/id_rsa':

It's generally a bad idea to run as root, so I'd recommend switching to another user account at your earliest convenience. (If you don't want to use your own account for whatever reason, you can create a single-purpose account to use instead.)

Scott Weldon
  • 9,673
  • 6
  • 48
  • 67
  • `ssh-add` return `Could not open a connection to your authentication agent.` – code-8 Oct 03 '16 at 22:34
  • 1
    Thanks for your suggestion, I will create a new user other than root to perform that. – code-8 Oct 03 '16 at 22:35
  • @ihue Updated my answer: you have to start the SSH agent first. – Scott Weldon Oct 03 '16 at 22:36
  • I tried `eval $(ssh-agent)` > `ssh-add` > work perfectly, by logging-out, and ssh back in, run `git pull` again, it prompt for password again. – code-8 Oct 03 '16 at 22:37
  • @ihue Yeah, that's by design: it's only cached for the current session. If you don't ever want to be prompted for a password, you'll need to generate a key that isn't password-protected. – Scott Weldon Oct 03 '16 at 22:41
  • @ihue Thanks for the edit, but I was just quoting what you had in your question. I reverted the latter part of your edit, because it invalidates part of my answer. – Scott Weldon Oct 03 '16 at 23:05
  • It's fine. Thanks for your helps ... – code-8 Oct 03 '16 at 23:15