1

在 Azure 应用服务实例中从 Kudu 的控制台运行 anpm install git+ssh://<git repo url>失败并出现以下错误:

npm ERR! Host key verification failed.
npm ERR! fatal: Could not read from remote repository. 

人们通常通过将主机的密钥添加到.ssh/known_hosts文件中来解决此错误。问题是正确的密钥已经存在。如果它不存在,git clone <git repo url>则会因相同的错误而失败,但事实并非如此。它成功克隆了存储库。

为了调试问题,我尝试DEBUG3通过~/.ssh/config文件将 SSH 的日志级别设置为,但输出没有改变(使用 时git clone,它会打印调试信息)。

因此,因此我怀疑问题在于npmAzure 中使用的 SSH 客户端没有考虑~/.ssh目录。

我的问题是,这是记录在某处还是错误?您知道错误在哪个组件中吗?

FTR,完整输出为:

npm ERR! git clone --template=D:\local\AppData\npm-cache\_git-remotes\_templates --mirror <git repo url> D:\local\AppData\npm-cache\_git-remotes\git-ssh-<git repo url>-dc8c35134031285cb7109c3e32618e85: Cloning into bare repository 'D:\local\AppData\npm-cache\_git-remotes\git-ssh-<git repo url>-dc8c35134031285cb7109c3e32618e85'...
npm ERR! git clone --template=D:\local\AppData\npm-cache\_git-remotes\_templates --mirror <git repo url> D:\local\AppData\npm-cache\_git-remotes\git-ssh-<git repo url>-dc8c35134031285cb7109c3e32618e85: 
npm ERR! git clone --template=D:\local\AppData\npm-cache\_git-remotes\_templates --mirror <git repo url> D:\local\AppData\npm-cache\_git-remotes\git-ssh-<git repo url>-dc8c35134031285cb7109c3e32618e85: Host key verification failed.
npm ERR! git clone --template=D:\local\AppData\npm-cache\_git-remotes\_templates --mirror <git repo url> D:\local\AppData\npm-cache\_git-remotes\git-ssh-<git repo url>-dc8c35134031285cb7109c3e32618e85: fatal: Could not read from remote repository.
npm ERR! git clone --template=D:\local\AppData\npm-cache\_git-remotes\_templates --mirror <git repo url> D:\local\AppData\npm-cache\_git-remotes\git-ssh-<git repo url>-dc8c35134031285cb7109c3e32618e85: 
npm ERR! git clone --template=D:\local\AppData\npm-cache\_git-remotes\_templates --mirror <git repo url> D:\local\AppData\npm-cache\_git-remotes\git-ssh-<git repo url>-dc8c35134031285cb7109c3e32618e85: Please make sure you have the correct access rights
npm ERR! git clone --template=D:\local\AppData\npm-cache\_git-remotes\_templates --mirror <git repo url> D:\local\AppData\npm-cache\_git-remotes\git-ssh-<git repo url>-dc8c35134031285cb7109c3e32618e85: and the repository exists.
npm ERR! Windows_NT 6.2.9200
npm ERR! argv "D:\\Program Files (x86)\\nodejs\\4.2.3\\node.exe" "D:\\Program Files (x86)\\npm\\3.5.1\\node_modules\\npm\\bin\\npm-cli.js" "install" "git+ssh://<git repo url>"
npm ERR! node v4.2.3
npm ERR! npm  v3.5.1
npm ERR! code 128



npm ERR! Command failed: git -c core.longpaths=true clone --template=D:\local\AppData\npm-cache\_git-remotes\_templates --mirror <git repo url> D:\local\AppData\npm-cache\_git-remotes\git-ssh-<git repo url>-dc8c35134031285cb7109c3e32618e85
npm ERR! Host key verification failed.
npm ERR! fatal: Could not read from remote repository.
npm ERR! 
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR! 
npm ERR! 
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     D:\home\site\foo\npm-debug.log
4

2 回答 2

0

所以对我来说,问题是我的应用服务是通过 Github 部署的,因此有一个部署密钥与它在 Github 上的 repo 相关联。
为了能够访问我的其他私人仓库,我需要执行以下操作。

在此之后,npm 会很高兴地安装我的私人仓库。

于 2020-05-29T12:12:56.947 回答
0

下面是 SSH 设置(配置文件、已知主机、公钥/私钥)在 Azure 应用服务上的处理方式:

  1. SSH 配置的默认文件夹是D:\home\.ssh. 这就是 Kudu 调试控制台中的 SSH 和 Git 使用的。

  2. 当您通过触发主机密钥生成https://your-site.scm.azurewebsites.net/sshkey?ensurePublicKey=1,它将创建D:\home\.ssh文件夹并将配置文件StrictHostKeyChecking no放入其中(以及新生成的 SSH 密钥)。这意味着通过调试控制台运行的 SSH 现在将自动接受主机密钥。

  3. Azure 应用服务上的 npm 需要%USERPROFILE%. 可以看到,第一次在 Debug Console 中运行 npm 时,会创建一个空文件夹%USERPROFILE%\.ssh

  4. 为了兼容 npm,Kudu 的部署脚本会将D:\home\.ssh文件夹复制到%USERPROFILE%(请参阅问题/修复)。每次通过 Web 应用程序的本地 Git 存储库、Github 或任何其他触发 Kudu 的部署选项进行部署时,都会发生这种情况。

  5. 根据我的经验,在缩放和重新启动应用程序时,将再次删除复制.ssh的文件夹。%USERPROFILE%

我认为在我的案例中发生的是,在调试不同的 npm/git/ssh 问题时,我重新启动了 Web 应用程序。npm install然后,我在调试控制台中手动运行时遇到了主机密钥验证问题。

于 2017-09-01T22:16:22.313 回答