ihue ihue - 2 months ago 13
Git Question

Not having to enter password for git pull in Ubuntu

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?

Answer

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.)