Getting permission denied error for a local repo in my company github, which I can clone successfully, however getting error for NPM install:
npm ERR! Error while executing:
npm ERR! C:\Program Files\Git\bin\git.EXE ls-remote -h -t git@<repo path and name>
npm ERR!
npm ERR! Permission denied (publickey).
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
If you want to use a password to access the SSH server, a solution for fixing the Permission denied error is to enable password login in the sshd_config file. In the file, find the PasswordAuthentication line and make sure it ends with yes . Find the ChallengeResponseAuthentication option and disable it by adding no .
GitHub's Permission denied (publickey) error is usually caused by one of the following three issues: You have used an incorrect email address in the GitHub SSH URL. You have not configured your public SSH key in your GitHub account. You must create GitHub SSH keys to be used by the secure shell.
Always use the "git" user $ ssh -T [email protected] > Permission denied (publickey). If your connection failed and you're using a remote URL with your GitHub username, you can change the remote URL to use the "git" user. You should verify your connection by typing: $ ssh -T [email protected] > Hi USERNAME!
Open Project settings>Repositories. To set the permissions for all Git repositories, choose Security. For example, here we choose (1) Project settings, (2) Repositories, and then (3) Security. Otherwise, to set permissions for a specific repository, choose (1) the repository and then choose (2) Security.
I ran into this problem and was not able to fix as all the solutions lacked one important step, so I am posting my answer in greater detail.
Assuming you have already generated ssh-key and added its public key to your github account. Also, assuming you are using Windows-10.
npm install
on Windows causes a lot of problems because there are ssh-agent
s running from 2 different sources:
Run start-ssh-agent
(to run git provided ssh-agent) and ssh-agent
(to run Windows provided ssh-agent) in cmd.
Go to task manager and click on details tab.
Look for ssh-agent.exe.
After following above steps, you can see 2 ssh-agent.exe running. In the 'User name' column you can see one for SYSTEM (this is provided by Windows) and one for your-user-name (this is git). Now, please close all ssh-agents you started for npm install(directly from task manager).
ssh-agent that npm install
is trying to use is from the git but it is being conflicted with the windows provided ssh-agent.
Git ssh-agent can be started using start-ssh-agent
but when you try to add ssh-key to your ssh-agent using command ssh-add -k ~/.ssh/id_rsa
, it is trying to access ssh-add.exe from Windows path but not picking ssh-add.exe from git.
Solution is to add ssh path of git to the Environment variables of your system and adding it before the "%SYSTEMROOT%\System32\OpenSSH" so it has higher priority.
This is only required so that you can access ssh-add.exe of git and after successful npm build you can freely remove it(even if you want to clone more repos and build them). Unless you want to add more keys for different repos.
Note: This path is different from the already present git/cmd path added during git installation so please make sure it is added before openSSh path variable for higher priority.
Please follow below steps to resolve your issue:
start-ssh-agent
in cmd. Don't use ssh-agent
as it starts the Windows provided ssh-agent.where ssh-agent
and where ssh-add
to test which ssh path will be preferred. (Hope you see 2 paths now and OpenSSH should not be appearing before Git/bin/usr path :) )start-ssh-agent
.(Runs git ssh-agent)ssh-add -k ~/.ssh/id_rsa
.(choose private key). (Adds keys to git ssh-agent, not Windows ssh-agent)npm install
.Note: After this, whenever you see the same error again, just run start-ssh-agent
and then npm install
.
I hope it works, and if you are not comfortable, after successful npm build you can even remove the newly added path from env. variables as it was required only once(to access ssh-add from git), and start-ssh-agent
is not accessed from that path.
Edit: It won't affect if you delete the path but I would recommend not to delete the path as this path also has many other useful tools like perl.exe, openssl.exe (don't need to install these tools separately).
Are you saying your lib is published to the npm registry or are you trying to use npm to install directly from github? It sounds like you're trying to do npm install company-org/repo-name
. If that's so then you're more than likely trying to get npm to pull from a private repo. You can clone because you've probably setup an SSH key for git to use to authenticate with Github.
Double check that SSH is setup and then use this syntax in package.json:
"package-name": "git+ssh://[email protected]:<company-org>/<repo>.git"
(note the use of colon instead of slash before company-org)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With