4

I am trying to install an npm package that pulls from our private repo. When I run npm install as myself, I get Please try running this command again as root/Administrator. When I run it as sudo, I get

npm ERR! Error: Command failed: 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.

I normally don't use sudo to do npm install. I think the issue is that when I run as sudo, it is looking in /var/root/.ssh for the key. I don't have the root user credentials, otherwise I would create a new key as root. Is there another work around?

EDIT: tried the suggestions below, they didn't work. However, the repo in questions is referenced by a dependency below the package root. `./node_modules//package.json. If I change the git url to use http, it works, but it's not a good idea to do it this way because I'll have to change it when I check the package back into the repo.

Musical Shore
  • 1,361
  • 3
  • 20
  • 41

2 Answers2

0

I think the issue is that when I run as sudo, it is looking in /var/root/.ssh for the key. I don't have the root user credentials

A workaround would be to change the url of that repo to an http one: it would then query for your login/password instead of relying on ssh keys which you cannot provide as root.

cd /path/to/private/repo
git remote set-url origin https://server/user/repo

If I change the git url to use http, it works, but it's not a good idea to do it this way because I'll have to change it when I check the package back into the repo.

Actually, you can change an url by another without modifying the config of the remote url.
For instance (as in How to use SSH instead of HTTP for Git submodules?)

git config url.https://github.com/.insteadOf ssh://git@github.com/
# or
git config url.https://github.com/.insteadOf git@github.com:
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • OK, but how is that different from changing the config? I am creating a new file that will be checked into the repo, and I am telling the config to use a different url. – Musical Shore Jan 29 '16 at 16:51
  • @MusicalShore because you can set it as global config (not changing the config of the repo itself: git config --global ... – VonC Jan 29 '16 at 16:53
  • That doesn't work either. I tried it as me and as sudo. In the npm output, I can see that it is still using ssh:// – Musical Shore Jan 29 '16 at 17:16
0

Try this: sudo /bin/bash then, run your npm command

Ulises
  • 9,115
  • 2
  • 30
  • 27
  • what's the error in this case? If you from you your user, let's say `mshore`, run `sudo /bin/bash` it should open a non-login terminal with root access but with `mshore's` environment. What happens when you do `sudo /bin/bash` from your repo's directory and then do `git pull` ? – Ulises Jan 29 '16 at 17:25
  • alright, that means basically that you're `root` and that you're ssh keys are being loaded from your user. if after `sudo /bin/bash` you do `whoami` it should output `root`. Just FYI once you are into to the root bash, you don't need to do `sudo npm ...` anymore. Just `npm ...`. – Ulises Jan 29 '16 at 17:39
  • The problem sort of went away on it's own, I may have inadvertently fixed it. However, I did look in /var/root/.ssh/known_hosts and my key was in there. – Musical Shore Jan 29 '16 at 19:17