Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Host key verification failed when installing NPM module from private Bitbucket

Tags:

git

npm

I am trying to install an NPM module from a private Bitbucket repository.

I can successfully run npm install locally on my system, but it fails on the server.

The error is:

npm ERR! Error while executing:
npm ERR! /bin/git ls-remote -h -t ssh://[email protected]/myorg/my-repo.git
npm ERR! 
npm ERR! 
npm ERR! (ssh-askpass:10260): Gtk-WARNING **: cannot open display: :0.0
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! exited with error code: 128

The strange thing is, cloning the repo on the server manually works fine: git clone [email protected]:myorg/my-repo

So the SSH keys are configured correctly.

like image 838
Ozzy Walsh Avatar asked Oct 18 '18 23:10

Ozzy Walsh


People also ask

Can I host npm packages privately in Bitbucket?

Here is a quick reference on hosting NPM packages privately in BitBucket. First, the contents of the NPM package needs to be committed to Bitbucket. The package.json must reside at the root of the repo.

Is there a way to verify the host key of Bitbucket?

No. Go to the repository -> Settings -> User and groups access "Host key verification failed"!!! Host key verification failed. nothing about authentication, so you are working on the wrong field. It means that the host key of the bitbucket.org is not in your ~/.ssh/known_hosts and your client does not have any way how to verify it.

What if I do not have an SSH key for Bitbucket?

If you do not have an SSH Key for BitBucket, please set one up using the following instructions: SSH Keys. For Heroku to pull from a private BitBucket repository, an SSH Key must be generated and registered as an Access key in the repository.

How to fix the “host key verification failed” error?

If there is no good reason for the host key to change, do not try to connect to that machine until you have resolved the situation. How to correct the “host key verification failed” error Method 1 – removing old key manually. 1. On the source server, the old keys are stored in the file ~/.ssh/known_hosts. 2.


2 Answers

That should indicate the npm command is not executed with the same account as the one used to manually clone the repo on the server.

In that npm account, the ~/.known_hosts would need to be updated first.

like image 146
VonC Avatar answered Nov 15 '22 03:11

VonC


I think you are accessing it from a Docker container, as you don't have ssh key added from docker container that problem exists. So there are two solutions for this

  1. Make your Git repository public which is not recommended

  2. npm install all the node modules on jenkins and then copy all the node modules to docker container. (Basically instead of npm installing on Docker container from package.json, do it on Jenkins and then copy those modules to container directly

The changes in docker file will be

INITIALLY :
FROM node:12.10-alpine
WORKDIR /app
RUN apk update \
  && apk add git
COPY node_modules /app
COPY . /app
ADD set_envs.sh .
RUN ["chmod", "+x", "set_envs.sh"]
EXPOSE 80
ENTRYPOINT ["/app/set_envs.sh"]


AFTER CHANGES :
FROM node:12.10-alpine
WORKDIR /app
COPY node_modules /app
COPY . /app
ADD set_envs.sh .
RUN ["chmod", "+x", "set_envs.sh"]
EXPOSE 80
ENTRYPOINT ["/app/set_envs.sh"]

And in shell script of Jenkins [in configure] add

npm install

That's it, it should work

like image 41
Sagar Maktha Avatar answered Nov 15 '22 04:11

Sagar Maktha