Vadim Vadim - 6 months ago 51
Git Question

Is there a way to specify which ssh key should be used for npm install

I have a private repo that I want to install in my package.json file.

"private-module": "git+ssh://"

By default npm uses your default private key. I want to be able to specify which ssh key npm should use when running
npm install
. Is there any way to do this?


Here are a few solutions:

  • Add an entry to your ~/.ssh/config. For example:

         IdentityFile ~/.ssh/bitbucket_key
         IdentitiesOnly yes
  • Use ssh-agent and add your key to the agent instance beforehand.

  • Use something like ssh-ident for choosing ssh agents and identities dynamically based on the current working directory or arguments passed to ssh-ident. As their readme states, you would typically alias ssh-ident to ssh so that it's automatically used everywhere.