【问题标题】:npm install fails HTTP authentication on Linuxnpm install 在 Linux 上的 HTTP 身份验证失败
【发布时间】:2018-10-21 17:03:02
【问题描述】:

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

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 一起使用来验证用户名和密码是否正确。

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

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

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

【问题讨论】:

  • user.name 是您的全名(如 John Smith),在您提交时使用。这不是远程站点上使用的登录名。我不知道您的 user.password 来自哪里,但它不是记录在案的 Git 配置变量。
  • 感谢您指出这一点!我一直发现 git 文档相当混乱,而且我一定在途中迷路了。我会再次查看git-credential-store

标签: git npm


【解决方案1】:

似乎明确指定.git-credentialsgit 的路径解决了这个问题。我用the following command这样做了:

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

【讨论】:

  • 是否有另一种方法可以做到这一点,而无需在文件中明确定义凭据?
  • @libzz 不幸的是,我找不到。可能有办法指定更安全的商店,但我不确定。
【解决方案2】:

@libzz,我无法评论接受的答案(我没有足够的声誉),但要回答您的问题:如果您不想存储您的凭据,您可以使用 'cache' 作为credentials.helper 设置。

git config --global credential.helper cache

如果您向 git 提供用户名/密码,它将缓存它们 15 分钟。

因此,在您的 npm install 之前,您可以在 repo 上执行类似 git pull 的操作,以让 git 提示并临时缓存您的凭据。在npm install 上,git 将能够使用您缓存的凭据从同一服务器进行克隆。

这消除了将您的凭据以纯文本形式存储的文件的需要。

【讨论】:

    【解决方案3】:

    我认为 bitbucket 不希望您从不受信任的来源进行连接。为此,您将需要一个受信任的密钥。问题已经解决:How to resolve authentication error in npm install?

    -- 这是这个人告诉你尝试的方法--

    如果可以,你应该:

    【讨论】:

    • 感谢您的回复。我不确定问题是否与不受信任的来源有关。在另一个目录中,我成功地在远程存储库上运行了git pullgit 让我输入Bitbucket 的用户名和密码,完成后,它成功通过了身份验证。我也尝试过使用 SSH 密钥路由,尽管使用的是 Bitbucket Cloud 文档,而不是您引用的那个人链接。不幸的是,我也遇到了这个问题。另外,我不太习惯使用它,因为它授予完全权限,而应用程序密码可能受到权限限制。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-14
    • 1970-01-01
    • 1970-01-01
    • 2018-03-10
    • 2015-04-27
    • 1970-01-01
    • 2014-01-24
    相关资源
    最近更新 更多