error: cannot run ssh: No such file or directory when trying to clone on windows
Asked Answered
H

9

81

I am trying to clone a remote repository on Windows, but when I did this:

git clone [email protected]:organization/xxx.git

I got this error:

error: cannot run ssh: No such file or directory
fatal: unable to fork

Am I missing something?

Hafner answered 24/9, 2012 at 17:9 Comment(0)
A
38

You don't have ssh installed (or don't have it within your search path).

You can clone from github via http, too:

git clone http://github.com/organization/xxx
Archibaldo answered 24/9, 2012 at 17:11 Comment(3)
when googling, i read that there is easier way in case i used cygwin (which is my case).Hafner
In this case, just install the ssh package. It's been a while since I worked with cygwin, but I think you just need to restart the setup and select the ssh package.Archibaldo
msysgit-- another alternative.Greenway
H
75

Check if you have installed ssh-client. This solves the problem on docker images, even when ssh keys are present.

On Debian images:

apt-get install openssh-client

On Alpine images:

apk add openssh-client
Hepcat answered 30/5, 2018 at 0:18 Comment(2)
The correct package name is openssh-clientSanborne
and RUN apk add openssh-client works on alpine image buildsEgress
A
38

You don't have ssh installed (or don't have it within your search path).

You can clone from github via http, too:

git clone http://github.com/organization/xxx
Archibaldo answered 24/9, 2012 at 17:11 Comment(3)
when googling, i read that there is easier way in case i used cygwin (which is my case).Hafner
In this case, just install the ssh package. It's been a while since I worked with cygwin, but I think you just need to restart the setup and select the ssh package.Archibaldo
msysgit-- another alternative.Greenway
T
9

Most likely your GIT_SSH_COMMAND is referencing the incorrect public key.

Try:

export GIT_SSH_COMMAND="ssh -i /home/murphyslaw/.ssh/your-key.id_rsa

then

git clone [email protected]:organization/xxx.git
Trichocyst answered 28/6, 2017 at 6:17 Comment(1)
Had the same error message but a different cause, 'ssh' missing from PATH; export GIT_SSH_COMMAND=/usr/bin/ssh fixed, thanks.Gloria
B
8

I am aware that it is an old topic, but having this problem recently, I want to bring here what I resolve my issue.


You might have this error on these conditions :

  • You use a URL like this : [email protected]:organization/repo.git
  • And you run a kind of command like this directly : git clone [email protected]/xxxxx.git whereas you don't have ssh client (or it is not present on path)
  • Or you have an ssh client installed (and git clone xxx.git work fine on direct command line) but when you run the same kind of command through a shell script file

Here, I assume that you don't want to change protocol ssh git@ to http:// ([email protected]:organization/repo.git -> http://github.com/organization/repo.git), like my case, cause I needed the ssh format.


So,

  • If you do not have ssh client, first of all, you need to install it
  • If you have this error only when you execute it through a script, then you need to set GIT_SSH_COMMAND variable with your public ssh key, in front of your git command, like this :

GIT_SSH_COMMAND="/usr/bin/ssh -i ~/.ssh/id_rsa" git pull

(Feel free to change it depending on your context)

Brittan answered 3/3, 2021 at 12:2 Comment(1)
Perfect answer, my bash script is working now. Thank you!Basrhin
B
3

I had this issue right after my antivirus moved the cygwin ssh binary to virus vault, and restored it after.

Symptoms:

  • SSH seems properly installed
  • SSH can be run from command line without problem

Another option before reinstalling ssh in this particular case: check the ssh command permissions

$ ls -al /usr/bin/ssh.exe
----rwxrwx+
$ chmod 770 /usr/bin/ssh.exe
Beaux answered 28/11, 2018 at 11:43 Comment(0)
P
2

I got the same error on the Alpine container in the CI-CD pipeline. I have added openssh package and it worked.

RUN apk add --no-cache git openssh

Pyrophoric answered 21/8, 2023 at 16:53 Comment(0)
D
0

You can try these as well

ssh-add ~/.ssh/identity_file
chmod 400 ~/.ssh/identity_file
Dituri answered 3/11, 2021 at 8:36 Comment(1)
400 revokes your own write access. That may or may not be what you actually want. 600 will permit writing as well as reading, for your own account only.Hairline
M
0

It so happened in my case that the new pair of ssh keys linked with my git account were not accessible.

I had to sudo chmod 777 ~/.ssh/id_rsa.* to resolve the issue.

Montane answered 23/3, 2022 at 12:26 Comment(1)
Whatever you are hoping to accomplish, chmod 777 is wrong and dangerous. You will want to revert to sane permissions ASAP (for your use case, probably chmod 600 or 640 or even 644 depending on the ownership and group) and if you have had world writable system files on a public-facing system, at the very least investigate whether it could have been breached and used as a pivot point for breaking into your organization’s network.Hairline
B
0

If your local drive is a mapped drive and you get that error message, consider changing directory to folder on local "C:" drive.

I encounted same message when I was on x:\\sys\windows_mapped_drive.

Once I cd to local c:\foobar\clone_project drive my git clone command worked.

Byproduct answered 16/7 at 20:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.