1

I'm attempting to run npm install git+https://bitbucket.org/User/Repository on Linux Raspbian 8.0. However, I get this error:

npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t https://bitbucket.org/User/Repository.git
npm ERR!
npm ERR! remote: Invalid username or password
npm ERR! fatal: Authentication failed for 'https://bitbucket.org/User/Repository.git/'
npm ERR!
npm ERR! exited with error code: 128

My Bitbucket username and app password should be available in both the global and directory git configs:

git config user.name "Username"
git config user.password "Password"
git config --global user.name "Username"
git config --global user.password "Password"

So, the correct username and password should be available for npm to use, but it doesn't seem to use them.

Also, for the avoidance of doubt, I have verified that the username and password are correct by using them with git directly.

Any help in resolving this issue would be much appreciated!

Edit Thanks to Matthieu Moy in the comments for pointing out that the config values I was using do not actually have any special meaning for Git.

According to documentation, username and password combinations can be stored in ~/.git-credentials. I have done so, in the form https://Username:Password@bitbucket.org. However, the same error as above persists. I have verified that the username and app password are otherwise correct. Git simply does not seem to be using them.

Chris Talman
  • 1,059
  • 2
  • 14
  • 24
  • 1
    `user.name` is your full name (like John Smith), used when you make a commit. It's not the login name used on remote sites. I don't know where your `user.password` comes from, but it's not a documented Git configuration variable. – Matthieu Moy Oct 21 '18 at 18:54
  • Thanks for pointing that out! I've been finding the git documentation fairly confusing and I must have got lost somewhere along the way. I'll look into `git-credential-store` again. – Chris Talman Oct 21 '18 at 19:18

3 Answers3

2

It seems that explicitly specifying the path of .git-credentials to git resolved the problem. I did so with the following command:

git config --global credential.helper 'store --file=/path/to/.git-credentials'
Chris Talman
  • 1,059
  • 2
  • 14
  • 24
2

@libzz, I can't comment on the accepted answer (I don't have enough reputation), but to answer your question: if you don't want to store your credentials you can use 'cache' as the credentials.helper setting.

git config --global credential.helper cache

If you supply a username/password to git, it will cache them for 15 minutes.

Thus, prior to your npm install, you can do something like a git pull on a repo to have git prompt and temporarily cache your credentials. On npm install git will be able clone from the same server with your cached credentials.

This eliminates the need to have a file with your credentials stored in plain text.

Chris
  • 94
  • 2
0

I think that bitbucket doesn't want you to connect from a non-trusted source. For that, you will need a trusted key. The problem has already been resolved: How to resolve authentication error in npm install?

-- Here is what the person tells you to try--

If you can, you should:

Gilbert Gabriel
  • 422
  • 2
  • 8
  • 23
  • 1
    Thanks for your response. I'm not sure the issue is about a non-trusted source. In a different directory, I successfully ran `git pull` on the remote repository. `git` asked me to input my username and password for Bitbucket, and after doing so, it successfully authenticated. I did also attempt to pursue the SSH key route, although using Bitbucket Cloud documentation, rather than the one the person you quoted linked. Unfortunately, I ran into issues with that as well. Plus, I wasn't comfortable using it, given that it grants full permissions, whereas app passwords can be permission-limited. – Chris Talman Oct 21 '18 at 18:39