Clone submodules on Windows Powershell not possible - windows

I have a project with a submodule configured. It uses a relative path, so it should be checked out via ssh (because I cloned the parent project with ssh).
I did:
git submodule update --init --recursive --remote
and the error is on Windows Powershell: Permission denied
I think I also found the reason for this. My ssh key is protected with a password. So powershell should ask me for the password as it does when using git clone. But apparently it does not.
So I got a few workarounds:
Use git bash on Windows (asks me for the passsword and thus works perfectly)
Don't use a password for ssh
Don't use ssh
All workarounds are not ideal. So I wonder: Is this a known issue / limitation? Can I do anything about this?

If those submodules are using an SSH URL (check your .gitmodules), then you can try and use an ssh-agent in your Powershell session.
Test it with ssh -Tv remoteUser#remoteServer (for GitHub remote repositories, that would be ssh -Tv git#github.com)
The first query should ask for your SSH passphrase, but after that, you should be able to clone/submodule update without any more prompt.

Related

How to git clone in wsl?

I try to clone a repo from a brand new Windows Install with wsl (Ubuntu 20.04).
What I did : generate SSH key and add public key to both github and framagit.
Tried
ssh -i -T git#github.com
And
ssh -i -T git#framagit.org
Both of them saied "Hello my pseudo, you're authentified"
But when I try to clone I have the following :
Without sudo :
Cloning into 'testaaa'...
error: chmod on /mnt/d/dev/dev/testaaa/.git/config.lock failed: Operation not permitted
fatal: could not set 'core.filemode' to 'false'
With sudo :
Cloning into 'testaaa'...
ssh: connect to host framagit.org port 22: Network is unreachable
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
What can I do to solve my issue?
You can fix this by following this guide. Summary below.
From a WSL prompt:
sudo vim /etc/wsl.conf
Add these lines:
[automount]
options = "metadata"
Save the file, shutdown wsl from a PowerShell prompt:
wsl --shutdown
Re-open a wsl terminal. You should see files owned by your user now instead of root. You can now git clone, chmod, chown etc.
You don't want to use sudo here, and in general there's no reason to need it with Git unless the repository you're working with is owned specifically by root.
The problem you're seeing is that you're using a Linux Git, which expects standard Unix permissions to work, on a file system (NTFS) that does not support them. Git will try to set the permissions appropriately when it rewrites the lock file which it will rename into places as the config file, but it can't do so, and it fails. Git for Windows doesn't have this problem because it maps these permissions differently from WSL, which just always returns an error.
You can try a couple of things:
Just clone the repository under WSL and not under a Windows drive. This is guaranteed to work, and should be fine.
Clone the repository somewhere under WSL and move it into a Windows drive, either setting the config options manually for Windows or trying git init again in the repository after cloning.
Run git init on the Windows drive and then do a git remote add origin YOUR-REMOTE and a git pull origin master (or whatever your branch is called).
It's possible that the last one may not work any better than what you have now, since git init may fail the same way.

Windows Git-bash fatal: Could not read from remote repository. when pushing through ssh

I'm using Windows Git-bash to push to my repository using ssh (not https). I have followed the instructions in this page
https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/
$ ssh-keygen -t rsa -b 4096 -C "barghouti_since88#hotmail.com"
$ ssh-add ~/.ssh/id_rsa
Then copied the key in ~/.ssh/id_rsa and copied it to my ssh keys in github account by following this setup
https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/
But now when I try to push using
$git add file
$git commit -m "adding file"
$git push
I'm getting the following
FATAL ERROR: Couldn't agree a key exchange algorithm (available: curve25519-sha256,curve25519-sha256#libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521)
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
There are a few possibilities you can examine:
did you "git clone" the repository with 'https' instead of 'git'? If
you want to git push with ssh, you need to clone with ssh as well.
is your Git for Windows version recent enough ? every once in a while, GitHub removes support for older, weaker, crypto, and your
software needs to match the server's algorithms, which in this case
it didn't, per the error message.
are you using the same ssh software as git ? Git for Windows comes with ssh included, but ssh can also have been installed separately,
on its own as OpenSSH, or included with putty, for instance. Compare
the output of 'where ssh-keygen' with the environment variable
GIT_SSH.
Hope this helps

Does SSH server need to be running in a unix style environment on remote client for GIT clone to work?

I am tasked to set up a central GIT repo internally for my team.
I'm working on getting this setup on a Windows Server 2012 R2 machine. To the best of my knowledge I've set this up correctly.
I have been following this tutorial but they use CopSSH which isn't free anymore so instead I installed Windows OpenSSH here: Install-Win32-OpenSSH.
On our windows server I've installed and configured the Windows OpenSSH along with GIT. Made the appropriate changes with regards to the environment variables and references needed.
On my local system (also windows) I've installed Putty and generated my public and private keys. The public key has been copied to the server and placed in the correct file. Using putty, I have verified my public/private key authentication is working.
On the server I created a git bare repository in the C: drive like so:
cd C:\
mkdir testing.git
git init --bare testing.git
I installed GIT on my local machine and run the command:
git clone ssh://name#host:port/testing.git
I always end up with the output:
Cloning into 'testing'...
fatal: ''/testing.git'' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I've tried different variations of this command with the same results and moving the testing.git file to the user home directory (C:\Users\name):
git clone ssh://name#host:port/c/testing.git
git clone ssh://name#host:port/~/testing.git
I've messed with permissions to explicitly give permissions for this user to access that directory.
It seems as though, maybe the git clone command cannot find the folder on the remote server. I started thinking that the SSH server itself needed to be running in a unix like environment like cygwin. Is this my issue? I've seen tutorials/walkthroughs of installing cygwin with openssh and this would be my next attempt.
Thanks for any help!
EDIT:
So I went ahead and installed Bitvise with their 30 day trial (to try) and everything works but this is only for 30 days. So this must mean that there is some set up issue with the Windows OpenSSH that I have?

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

I am trying to clone a remote repository on Windows, but when I did this:
git clone git#github.com:organization/xxx.git
I got this error:
error: cannot run ssh: No such file or directory
fatal: unable to fork
Am I missing something?
Check if you have installed ssh-client. This solves the problem on docker machines, even when ssh keys are present:
apt-get install openssh-client
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
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 git#github.com:organization/xxx.git
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 : git#github.com:organization/repo.git
And you run a kind of command like this directly : git clone git#github.com/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://
(git#github.com: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)
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
You can try these as well
ssh-add ~/.ssh/identity_file
chmod 400 ~/.ssh/identity_file
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.

Git fatal: remote end hung up

So I thought I had finally got everything setup on Windows ... then ran into this issue.
Current setup
URL: ssh://user#host:port/myapp.git
Already run Putty - and can connect using valid .ppk keys through the ~/.ssh/authorized_keys direct. In Git and TortoiseGIT - I set both to use "plink.exe".
Putty works fine - no issues - but when I run that URL into bash I get for a git clone (url)
fatal: the remote end hung up expectedly
In a cygwin bash terminal - running "ssh user#host" - works no probs at all.
Anyone suggest anything?
I found out that using ssh.exe from the Git package works every time, as opposed to the ssh that comes with cygwin (the default).
Using this exported variable seems to help; it's slower (2x or more) but it's more stable. Take it as another workaround.
$ export GIT_SSH=/cygdrive/c/Program\ Files/Git/bin/ssh.exe
FYI:
This version of Msysgit comes with OpenSSH 4.6p1, OpenSSL 0.9.8e. [works]
Cygwin's SSH is OpenSSH 5.5p1, OpenSSL 0.9.8n. [doesn't work]
I had the same problem with plink for git under windows.
On run of plink.exe -v xxx#host.com it started to show
Pageant is running. Requesting keys.
Pageant has 1 SSH-2 keys
login as: <<< trouble
Instead of
Pageant is running. Requesting keys.
Pageant has 1 SSH-2 keys
Using user "xxx"
To resolve this problem I cleaned up the putty registry records and sessions by
putty.exe -cleanup
After that plink starts afresh and asks to trust and store the host again and it is getting connected with no problem !
Try following steps, maybe something will give you a hint on your problem:
1. Run putty and after setting up server name/user name/keys etc. save those settings.
2. Run plink.exe or plinkw.exe like plink.exe user_name#server, (it'll throw some info at you) just to see if plink can connect to the server.
3. Check again that git knows that it should use plink, I'd say with all VCSs, that's the problem people have most often, apart from their keys not being set up properly.
Normally by now most of your ssh problems would be revealed. Now just fix them. :)
Update:
I think the problem you have is caused by several gits you've got installed. For the msysgit and cygwin git you'd need to set the GIT_SSH variable. That's done via either 'set GIT_SSH=c:\path\putty\plink.exe' or 'export GIT_SSH=/your/path/putty/putty.exe' respectively. If you're also using tortoise git, you'd need to locate 'properties' (or is it settings?) in it's menu, and set the ssh client there.
Apart from all that, when specifying git clone URL, use your login name and the server name in there, e.g. 'git clone ssh://user#server/your/path/repo.git User and server names should be used by plink, and plink should be able to connect to the server with those arguments, when all of those requirements are met, you'll be all set.
Good luck.
If you want to try the cygwin openssh 5.4p1-1, which does seem to work for this, unlike 5.5 or 5.6, you can use the cygwin time machine mirrors. Start setup.exe with -X and add a mirror Url, such as:
ftp://www.fruitbat.org/pub/cygwin/circa/2010/05/20/230133
Be careful not to install too much, i.e. base packages, from an older mirror than the rest of your install.
We had same problem and here is solution how we solved the problem:
at first we got:
zajdan#cyberFuture:~$ git clone ssh://nette#19X.16X.14X.7X/~repos/erotika.git/ erotika
Initialized empty Git repository in /home/zajdan/erotika/.git/
Password:
fatal: '/repos/erotika.git': unable to chdir or not a git archive
fatal: The remote end hung up unexpectedly
zajdan#cyberFuture:~$
solution:
zajdan#cyberFuture:~$ git clone ssh://nette#19X.16X.14X.7X/~/repos/erotika.git/ erotika
after tilde there must be a slash!
I have exactly the same issue.
I don't use Putty (just Cygwin).
I use Windows 7 Ultimate (fully patched as of this moment).
I just installed Cygwin yesterday.
I made sure binary mounts were being used.
If I copy a git repo to the machine (via samba mount), I can clone it, but when I "git diff" after the clone, there are a bunch of "different" files with no diffs. After a "git status" there was no output from "git diff". It seems like a newline thing, but I can't figure out how that would be happening. (I have igncr in SHELLOPTS, but removing that doesn't fix it.)
I'm completely stumped.
Check the openssh version you're using in CygWin. Version 5.5p1-1 (which is the latest at this time) gave me the same error. Downgrading to 5.4p1-1 fixed the problem.
Another solution would be to use putty/plink instead of openssh.
For more details, see this thread: http://www.mail-archive.com/cygwin#cygwin.com/msg103752.html
I get message: "remote end gung-up, unexpected EOFs, index-pack failed" while cloning git repo but was able to workaround this issue with copssh http://sourceforge.net/projects/sereds/files/Copssh
The root cause is Cygwin openssh package.
I removed original openssh from Cygwin, installed copssh and set GIT_SSH variable to point copssh binaries. After this I simply added copssh binaries in the PATH and now I'm using copssh instead of openssh - there is no difference.
Everything works fine and issue does not appear any more.
The other solution is to use mSysGit package.
I believe the real problem is that cygwin's ssh looks for .ssh in /home/name/.ssh and mingw's git ssh looks for .ssh in c:/user/name/.ssh
Chances are your keys are in one and only one of these directories.
You can trying telling cygwin's .ssh to use a different identity file using the -i switch, or move the keys into both directories, or create an ssh config file in /home/name/.ssh/config.
I created a config that contains:
Host github.com
User jerryasher
Hostname github.com
IdentityFile c:/Users/jerry/.ssh/id_rsa
And given that I can use either the mingw git from git bash or cygwin's git from an rxvt to interact with github.
To correct this issue, run "plink -agent github.com"
Press y when prompted to cache the key. Login as git. You'll automatically be disconnected. And it sould work.
Source: http://devlicio.us/blogs/sergio_pereira/archive/2009/05/06/git-ssh-putty-github-unfuddle-the-kitchen-sink.aspx
Try to use absolute path to repo in a URL, that worked for me.
Instead of:
git ssh://user#host:port/myapp.git
Write:
git ssh://user#host:port//home/user/repo/myapp.git
Notice the double slash!

Resources