With Windows now beginning to ship its own distribution of OpenSSH, it would be useful to be able to omit the bundled OpenSSH distribution to allow the systems OpenSSH distribution to be used. At present, the two appear to conflict (the Windows ssh-agent is not detected by GFW's OpenSSH binary).
$ git --version --build-options
git version 2.16.2.windows.1
cpu: x86_64
built from commit: e1848984d1004040ec5199e749b5f282ddf4bb09
sizeof-long: 4
$ cmd.exe /c ver
Microsoft Windows [Version 10.0.17115.1]
(c) 2017 Microsoft Corporation. All rights reserved.
# One of the following:
> type "C:\Program Files\Git\etc\install-options.txt"
> type "C:\Program Files (x86)\Git\etc\install-options.txt"
> type "%USERPROFILE%\AppData\Local\Programs\Git\etc\install-options.txt"
$ cat /etc/install-options.txt
Editor Option: VIM
Path Option: Cmd
SSH Option: OpenSSH
CURL Option: WinSSL
CRLF Option: LFOnly
Bash Terminal Option: ConHost
Performance Tweaks FSCache: Enabled
Use Credential Manager: Enabled
Enable Symlinks: Enabled
Any other interesting things about your environment that might be related
to the issue you're seeing?
PS>gcm ssh-agent | Select Name,Version,Source
Name Version Source
---- ------- ------
ssh-agent.exe 1.0.0.0 C:\Windows\System32\ssh-agent.exe
PS>gcm ssh | Select Name,Version,Source
Name Version Source
---- ------- ------
ssh.exe 1.0.0.0 C:\Windows\System32\ssh.exe
ConEmu + PowerShell
add-sshkey # successful
ssh-add -l # shows key as expected
cd $myGitRepo
git pull
My local repository should have been updated
Error:
Could not create directory '/Users/brian/.ssh'.
The authenticity of host 'github.com (192.30.253.112)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/Users/brian/.ssh/known_hosts).
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
https://github.com/bgshacklett/extropy
I was able to resolve the above scenario by renaming ssh.exe in the $gitPath/usr/bin directory to ssh.exe.old, forcing it to use the system's ssh.exe binary.
This is an excellent suggestion! I'll give you enough pointers to get started and then kick the project right back into your court.
This is now as easy as cloning https://github.com/git-for-windows/git-sdk-64 and double-clicking the git-bash.exe in the cloned worktree. As the repository is a bit big, and you really only need the latest revision, it is best to make a shallow clone:
git clone --depth=1 https://github.com/git-for-windows/git-sdk-64
For this, you need to call
sdk build installer
This is where the fun starts. The program telling the installer what to do is in /usr/src/build-extra/installer/install.iss. You will want to open this in an editor and run sdk build installer in you Git SDK Bash to test.
This is in the [Components] part of the program. You will already see the option for the updater (called autoupdate) and you can add the component there. I would suggest to give it the description "Use native OpenSSH".
ssh.exe if the component is selectedA bit counterintuitively, when this "component" is enabled, we have to remove something. This should be done close to the lines adding the autoupdate feature (look for "Install a scheduled task to try to auto-update Git for Windows") and you'll see it. It should be as straight-forward as
{
When the user prefers the native OpenSSH, use that instead of our bundled one.
}
if IsComponentInstalled('nativeopenssh') then begin
if not DeleteFile(AppDir + '/usr/bin/ssh-add.exe') or
not DeleteFile(AppDir + '/usr/bin/ssh-agent.exe') or
not DeleteFile(AppDir + '/usr/bin/ssh-copy-id') or
not DeleteFile(AppDir + '/usr/bin/ssh-keygen.exe') or
not DeleteFile(AppDir + '/usr/bin/ssh-keyscan.exe') or
not DeleteFile(AppDir + '/usr/bin/ssh-pageant.exe') or
not DeleteFile(AppDir + '/usr/bin/ssh.exe') or
not DeleteFile(AppDir + '/usr/bin/sshd.exe') then
LogError('Line {#__LINE__}: Unable to uninstall bundled OpenSSH');
end;
ssh.exe is available, and hide the component otherwiseYou will only want to offer this option when the native OpenSSH is available, and then make it the default. To this end, you will want to add a [Check parameter] to the component, and implement a function that tests whether native OpenSSH is available. I would imagine that native OpenSSH is installed always into the same location, or has a registry entry we can check?
Of course we will want to use native OpenSSH by default! (I guess...)
If this is something we will want to support, then we should enable the component by default. I found only one way to do this in a quick web search: https://stackoverflow.com/questions/32309002/inno-setup-set-default-component-depending-on-system-language#comment52493771_32309002
Essentially, you will have to add code to InitializeSetup that will cycle through WizardForm.ComponentsList.ItemCaption[i] until you find the one about native OpenSSH, and then call if (WizardForm.ComponentsList.ItemEnabled[i]) WizardForm.ComponentsList.Checked[i]:=True;.
Of course, we may want to be quite a bit more careful about that... for example, we need to make sure that the existing OpenSSH configuration (in %USERPROFILE%\.ssh) will be used by the native OpenSSH, too? Otherwise, we would break existing users' setups, which is no good...
Awesome! I'll see what I can do.
Note: I was just made aware that the GIT_SSH=%SystemRoot%\System32\OpenSSH\ssh.exe method does not work when using a 32-bit Git. The reason is that 32-bit processes see a different %SystemRoot%\System32 than 64-bit processes (provided they're running on a 64-bit Windows). But there is a trick to make it work, still: replace the System32 by SysNative, i.e. GIT_SSH=%SystemRoot%\SysNative\OpenSSH\ssh.exe.
One other caveat: if you have configured anything in your $HOME/.ssh/config via MSYS2-compatible paths (e.g. IdentityFile /d/keys/1st.key), the native OpenSSH won't be able to use that correctly. Users will need to change this to Windows-compatible paths, for example d:/keys/1st.key.
I don't suppose you could give me some advice on how to test a function, by chance? I think I'm about 90% of the way there, but I'm not having much luck working with PascalScript.
I just got the build-extra repo connected to my own fork. Here's a diff of what I have so far:
https://github.com/git-for-windows/build-extra/compare/master...bgshacklett:1556
@bgshacklett my favorite way of testing a function is to call it in the code that builds the custom pages, and then running ./installer/release.sh --debug-wizard-page=Editor.
Hmm. This ticket has stalled. Let's close it.
Most helpful comment
@bgshacklett my favorite way of testing a function is to call it in the code that builds the custom pages, and then running
./installer/release.sh --debug-wizard-page=Editor.