首页 > 解决方案 > npm install 在 Linux 上的 HTTP 身份验证失败

问题描述

我正在尝试npm install git+https://bitbucket.org/User/Repository在 Linux Raspbian 8.0 上运行。但是,我收到此错误:

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

我的 Bitbucket 用户名和应用程序密码应该在全局和目录 git 配置中都可用:

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

因此,应该可以使用正确的用户名和密码npm,但似乎没有使用它们。

另外,为免生疑问,我已经通过直接使用它们来验证用户名和密码是否正确git

解决此问题的任何帮助将不胜感激!

编辑 感谢 Matthieu Moy 在评论中指出我使用的配置值实际上对 Git 没有任何特殊含义。

根据文档,用户名和密码组合可以存储在~/.git-credentials. 我已经这样做了,形式为https://Username:Password@bitbucket.org。但是,与上述相同的错误仍然存​​在。我已验证用户名和应用程序密码是否正确。Git 似乎根本没有使用它们。

标签: gitnpm

解决方案


似乎明确指定解决问题的.git-credentials路径git。我使用以下命令这样做:

git config --global credential.helper 'store --file=/path/to/.git-credentials'

推荐阅读