Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yarn add <git remote url> returns "Permission denied" error #686

Closed
szemek opened this issue Oct 11, 2016 · 39 comments
Closed

yarn add <git remote url> returns "Permission denied" error #686

szemek opened this issue Oct 11, 2016 · 39 comments
Labels

Comments

@szemek
Copy link

szemek commented Oct 11, 2016

Do you want to request a feature or report a bug?

bug

What is the current behavior?

yarn add returns "Permission denied" error

➜  yarn add git@github.com:szemek/cheatsheets.git
yarn add v0.15.1
[1/4] πŸ”  Resolving packages...
error Command failed.
Exit code: 128
Command: git
Arguments: clone github.com:szemek/cheatsheets.git /Users/szemek/.yarn-cache/.tmp/087b27ef145b8d7861743348d6045535
Directory: /Users/szemek/project
Output:
Cloning into '/Users/szemek/.yarn-cache/.tmp/087b27ef145b8d7861743348d6045535'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
    at SpawnError (/Users/szemek/.yarn/lib/errors.js:18:1)
    at ChildProcess.proc.on.code (/Users/szemek/.yarn/lib/util/child.js:107:15)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:850:16)
    at Socket.<anonymous> (internal/child_process.js:323:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at Pipe._handle.close [as _onclose] (net.js:485:12)
info Visit http://yarnpkg.com/en/docs/cli/add for documentation about this command.

If the current behavior is a bug, please provide the steps to reproduce.

yarn add git@github.com:<user>/<repository>.git

What is the expected behavior?

As you can notice in: Arguments: clone github.com:szemek/cheatsheets.git /Users/szemek/.yarn-cache/.tmp/087b27ef145b8d7861743348d6045535

git@ shouldn't be stripped from git remote url.

Note: it doesn't matter that mentioned repository doesn't contain package.json. For my private repository with https protocol it worked just fine.

Please mention your node.js, yarn and operating system version.
node.js v6.0.0
yarn 0.15.1
OS X 10.11.6

@sebmck sebmck added the cat-bug label Oct 11, 2016
@stephenlacy
Copy link
Contributor

@natecox
Copy link

natecox commented Oct 12, 2016

Issue confirmed for me as well, I'm unable to add a git remote directly as specified above.

troydemonbreun added a commit to troydemonbreun/yarn that referenced this issue Oct 12, 2016
@danharper
Copy link
Contributor

This doesn't work with npm either: npm install git@github.com:szemek/cheatsheets.git, are you sure this should work? Are you missing the protocol?

@natecox
Copy link

natecox commented Oct 12, 2016

Absolutely, assuming you add the protocol as required.

In fact, this line from my package.json is preventing me from actually trying yarn right now:
"postcss-brunch": "git+ssh://git@github.com:brunch/postcss-brunch.git#b361e97",

You can try for yourself with
npm install git+ssh://git@github.com:brunch/postcss-brunch.git#b361e97

@danharper
Copy link
Contributor

danharper commented Oct 12, 2016

Ah, I've got a PR to fix that one here: #934

That specifically is an issue with the auth segment of the URL (git@).

@danharper
Copy link
Contributor

Ohh, it doesn't work with the SSH syntax either, though.

danharper added a commit to danharper/yarn that referenced this issue Oct 12, 2016
need to add tests, make sure it didn’t break other things.

general idea is: for a URL like
β€œssh://git@github.com:radweb/eslint-config-radweb.git”, the β€œ:” needs
replacing for the Git to fetch it.

secondly, after add, the β€œversion” in the package.json was getting
butchered to β€œgithub:radweb/eslint-config-radweb”. giving exotic
resolvers higher priority fixes this.

i think similar code exists elsewhere, need to check.
@danharper
Copy link
Contributor

danharper commented Oct 12, 2016

I've got a fix prepared for SSH URLs. Need to add tests and check a few other places too, but it's late here so I'll continue tomorrow danharper@2eaf66d (explanation is in the commit message)

@troydemonbreun
Copy link
Contributor

@danharper cool, since you are moving exotic resolvers higher priority, see if you can remove this code, as moving the priority might resolve #59 and make this code unnecessary?

@danharper
Copy link
Contributor

@troydemonbreun I've got a PR open for that here: #934. Basically replaces that block with a protocol check instead.

troydemonbreun added a commit to troydemonbreun/yarn that referenced this issue Oct 13, 2016
@szemek
Copy link
Author

szemek commented Oct 15, 2016

This doesn't work with npm either: npm install git@github.com:szemek/cheatsheets.git, are you sure this should work? Are you missing the protocol?

@danharper I checked npm (v3.8.6) installation. It returns:

npm ERR! Unsupported URL Type: github.com:szemek/cheatsheets.git

For me it's better information than misleading error with lack of access.

Thanks for working on this πŸ‘

@joseph-allen
Copy link

Thanks for working on this πŸ‘

@ContiGabriel
Copy link

Hi,
Is this issue resolved in the latest version?

@jbruni
Copy link

jbruni commented Nov 14, 2016

I have just tried on latest nightly (0.18.0-20161114.1729) and the issue remains.

Is there a workaround? Is this bug difficult to resolve? It seems to simple to avoid mangling the git URL we inform in the command line...

@aleclarson
Copy link

aleclarson commented Jan 14, 2017

This works: npm i --save git+ssh://gitlab.com/user/repo.git#1.0.0

This doesn't work: yarn add git+ssh://gitlab.com/user/repo.git#1.0.0

With or without the #1.0.0 part.

yarn add v0.18.1
info No lockfile found.
[1/4] πŸ” Resolving packages...
error Command failed.
Exit code: 128
Command: git
Arguments: clone ssh://gitlab.com/user/repo.git /Users/aleclarson/Library/Caches/Yarn/.tmp/7a49a436907360ab3ea50e6a2a82f300
Directory: /Users/aleclarson/lib/modules/foo
Output:
Cloning into '/Users/aleclarson/Library/Caches/Yarn/.tmp/7a49a436907360ab3ea50e6a2a82f300'...
Permission denied (publickey).
fatal: Could not read from remote repository.

EDIT

Here's the workaround:
yarn add git+ssh://git@gitlab.com/user/repo.git#1.0.0

Notice the git@ before gitlab.com

@arcanis
Copy link
Member

arcanis commented Apr 28, 2017

The original issue doesn't seems like a bug, in that Yarn is (somewhat rightfully) trying to install the git package from the location github.com:szemek/cheatsheets.git. We could special-case this in order to solve the ambiguity for git@github.com, but it seems like the best fix would be to use git+ssh urls.

I'm going to close this issue for triage, but discussion is still open.

@arcanis arcanis closed this as completed Apr 28, 2017
@jbruni
Copy link

jbruni commented Apr 30, 2017

Why close the issue rather than fix it? Community wants it working and is contributing for its solution.

@jbruni
Copy link

jbruni commented Apr 30, 2017

As far as I understood, the fix relies on simply letting the URL informed in the command line as it is, instead of changing it to some kind of guess.

@arcanis
Copy link
Member

arcanis commented Apr 30, 2017

@jbruni There's an ambiguity in the command line grammar. If you write foo@bar.com:a/b, it can be interpreted as either the foo package at bar.com:a/b, or the package located at foo@bar.com:a/b. Considering you can still install the package by resolving the ambiguity (by using a git+ssh:// protocol) and that reversing this behavior would remove this ability to solve the ambiguity, I'm not sure this is something worth special-casing. How do you suggest we fix it?

@jbruni
Copy link

jbruni commented May 3, 2017

Maybe we can improve the ambiguity resolution strategy - since in this case it is failing.

Maybe we can keep it as it is, but if there is a fail to install that package, then it could "make another guess", ie, assume the other possibility of interpretation is correct, and try it.

@sebastiaanluca
Copy link

Tried all variations mentioned here, none works. So how to add package by branch or commit? :/

@gulderov
Copy link

only http works for me now:
yarn add https://github.com/yarnpkg/yarn.git#20e5779ec324b3103ef9cca14ce9f96d29fd93c6

@joint-song
Copy link

I also got this error, and checked the git config and repo auth setup, but got nothing. Then removed nvm, node(installed from brew), yarn(installed from brew), then just install node from official web, and yarn from npm. Did not install nvm. Then, it's allright!!!
I cannot able to explain why it is. Maybe nvm or not. Hope can help anyone.
url pattern of installed pkg in package.json:
"pkgFoo": "git+ssh://git@host:opensource/foo.git#xxx"

@eduardonunesp
Copy link

In my case it was asking for my password, then for some reason it always failing with this same error, after the command ssh-add -K it stops to fail

@daviskoh
Copy link

seeing this in yarn 0.27.5 and @aleclarson's solution did not work although npm install works. Is this an issue again?

@BYK
Copy link
Member

BYK commented Aug 24, 2017

@daviskoh can you try with the latest nightlies?

Also what is your git version? Are you using a proxy for git etc.?

@alexhalf
Copy link

alexhalf commented Aug 28, 2017

For me it worked with 0.25.2 with my ssh keys (for bitbucket) in pageant, but it does not work with 0.27.0
git --version
git version 2.7.0.windows.1
from log: uri for repository: clone git@bitbucket.org:.....
!but in my package.json and yarn.lock the URI is: git+ssh://git@bitbucket.org:....

@daviskoh
Copy link

@BYK it worked after adding the following to my ~/.ssh/config:

Host *
    AddKeysToAgent yes

and forcing a pull / push on the private repo 1st I'm guessing to "show" I have permissions on it. Cant remember which user and which git issue suggested to do this as there are a lot of similar issues.

My git version: 2.11.0

@codingwesley
Copy link

@natecox thanks your anwser! git url must add prefix git+ssh://[url] good resolve!

@t1gor
Copy link

t1gor commented Dec 5, 2017

The funny part is that I'm trying to do the same with Yarn & Phabricator (both FB technology) and it also doesn't seem to work (only over https). Connection simply timesout.

@honavar-sohan
Copy link

hey I am facing the same issue but I also have a passphrase on my ssh which is why i am getting Permission denied

@keego
Copy link

keego commented Apr 18, 2018

Was hitting this issue as well and prefixing with git+ssh:// helped me as well. Here's the final line that worked for me: yarn add git+ssh://git@github.com:keego/ros3djs.git#ES6_ONLY

Note: this is a public repo so I didn't have any permission issues

@mikebridge
Copy link

I am hitting the same Permission denied (publickey) during yarn install with yarn 1.7.0 on PowerShell/Windows when trying to access a private git repo using a url like this:

"dependencies": {
   "git+ssh://git@github.com/MyUser/MyRepo.git#abcdef1234..."
}

This is with ssh-agent running. I can access the private repo fine from git on the command line. npm install also works fine.

@mikebridge
Copy link

mikebridge commented Jul 10, 2018

It looks like my problem came from using the new OpenSSH for Windows 10. I uninstalled this via "Manage Optional Features" (which required a reboot), and then installed posh-git. After running start-sshagent I was able to run yarn install from PowerShell.

Although I use git on WSL everywhere else, this requires git for windows.

@temurih
Copy link

temurih commented Jul 13, 2018

THIS DOES NOT WORK IF YOU WANT TO SETUP WITH PASSPHRASE.

  • cd ~/.ssh or on Windows go to C:\Users\<username>\.ssh and open GitBash/Cygwin there.
  • run ssh-keygen
  • It will ask for optional filename and passphrase. By default the filename will be id_rsa.pub
  • Open the generated file (by default id_rsa.pub) and copy the key inside. (ctrl+A and ctrl+C)
  • Login to your GitHub. Profile Icon from top right > Settings > SSH keys and GPG keys > New SSH key.
  • Give it a title, and paste below the SSH key that we copied earlier.
  • It should now resolve this error git@github.com: Permission denied (publickey)

@mikebridge
Copy link

Does this work if you have a passphrase set?

@temurih
Copy link

temurih commented Jul 13, 2018

@mikebridge, no it does not work with passphrase. :(

@daku
Copy link

daku commented Jul 27, 2018

yarn add git://github.com/<username>/<package name>.git

@paschalidi
Copy link

paschalidi commented Nov 21, 2018

getting the same error on

node version : 8.0.0
yarn version : v1.5.1

when running yarn on docker image 'node:8.10.0'

my package dependencies look like this

  "dependencies": {
    "prop-types": "^15.6.2",
    "react": "^16.6.0",
    "react-dom": "^16.6.0",
    "react-router": "^4.3.1",
    "react-router-dom": "^4.3.1",
    "rx-connect": "git://github.com/herman-rogers/rx-connect.git#lib",
    "rxjs": "^6.3.3",
    "styled-components": "^3.4.10"
  }

Build fails when yarn is executed with the following errors

+ yarn

yarn install v1.5.1

[1/4] Resolving packages...

[2/4] Fetching packages...

warning Pattern ["core-js@latest"] is trying to unpack in the same destination "~/.cache/yarn/v1/npm-core-js-2.5.7-f972608ff0cead68b841a16a932d0b183791814e" as pattern ["core-js@^2.5.7","core-js@^2.2.0","core-js@^2.5.3","core-js@^2.4.0","core-js@^2.5.0","core-js@^2.2.0","core-js@^2.5.0"]. This could result in non-deterministic behavior, skipping.

error An unexpected error occurred: "Command failed.

Exit code: 128

Command: git

Arguments: clone git://github.com/herman-rogers/rx-connect.git ~/.cache/yarn/v1/.tmp/422be2b3c5a69d0ac7b460ec5dc102ae

Directory: /home/ec2-user/workspace/vitaTeam_uvita-webapp_PR-86-MYDWWK7BGXIUJU5B3TBMMRJIVK6ZBXDR5S2PET2RO5MXSNNAHTRA

Output:

Cloning into '~/.cache/yarn/v1/.tmp/422be2b3c5a69d0ac7b460ec5dc102ae'...

fatal: unable to look up current user in the passwd file: no such user".

info If you think this is a bug, please open a bug report with the information provided in "/home/ec2-user/workspace/vitaTeam_uvita-webapp_PR-86-MYDWWK7BGXIUJU5B3TBMMRJIVK6ZBXDR5S2PET2RO5MXSNNAHTRA/yarn-error.log".

info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

script returned exit code 1

@yaseen-h0
Copy link

in my case it was due to the key having a passphrase
It seems they don't prompt for a password and just show a permission denied.
#3699
Following their suggestion to use an ssh-agent resolved it
ssh-add ~/.ssh/id_rsa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests