Feature request: Support for putty/plink ssh.variant (Windows-specific)
Apologies in advance for another Windows-specific problem. 🫣
On Windows, putty/plink is quite popular as SSH alternative for Git access. Right now, https://github.com/gitbutlerapp/gitbutler/blob/7dda61127533103575b83e271b2f9f80bbaa170e/crates/gitbutler-git/src/repository.rs#L166 seems to indiscriminately insert a "-o" param that's not supported by "plink.exe" or "TortoisePLink.exe" (from TortoiseSVN/TortoiseGit).
I found https://www.kolossi.co.uk/git-plink-unknown-option-o/ that shows the usual fix to get Putty/plink working. In my case, my Windows Git installation has the variant as "putty", not "plink", though:
file:C:/Program Files/Git/etc/gitconfig ssh.variant=putty
This is choosable while running the Git for Windows installer.
Subsequent GB error message:
Git push failed Your branch cannot be pushed due to an unforeseen problem. Please check our [documentation](https://docs.gitbutler.com/troubleshooting/fetch-push) on fetching and pushing for ways to resolve the problem.
git command exited with non-zero exit code 128: ["push", "--quiet", "origin", "87f8301baf2e2c1981169e3df0e9815efead053e:refs/heads/feature/rotated_content"] STDOUT: STDERR: plink: unknown option "-o" plink: unknown option "-o" fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
Also, please note that before running into the problem with the "-o" parameter. I got the following due to a space in the GIT_SSH env variable:
Git push failed Your branch cannot be pushed due to an unforeseen problem. Please check our [documentation](https://docs.gitbutler.com/troubleshooting/fetch-push) on fetching and pushing for ways to resolve the problem.
git command exited with non-zero exit code 128: ["push", "--quiet", "origin", "87f8301baf2e2c1981169e3df0e9815efead053e:refs/heads/feature/rotated_content"] STDOUT: STDERR: C:\\Program Files\\TortoiseSVN\\bin\\TortoisePlink.exe -o StrictHostKeyChecking=accept-new -o KbdInteractiveAuthentication=no: C:\Program: No such file or directory fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
Moving the plink executable to a path without spaces moved me along but resulted in the issue that prompted this ticket.
In the meantime, I'll try to set up an SSH executable instead of plink.
Work-around for me was the following:
- I'm using KeePass 2 with KeeAgent plugin.
- I had to "Enable agent for Windows OpenSSH" in the Plugin options and let it create a Cygwin/MSYS compatible socket file.
- I set a user-level env variable SSH_AUTH_SOCKET to "C:/Somepath/SSH_AUTH_SOCK/cygwin_ssh.sock" (i.e. the file I configured in the step above. Also note the forward slashes instead of backslashes. Single backslashes get stripped.)
- In the project-level .git/config file I set:
[core]
sshCommand = \"C:\\\\Program Files\\\\Git\\\\usr\\\\bin\\\\ssh.exe\"
[ssh]
variant = ssh
GitButler was now able to fetch from the Git repo. Onto the next GB error message...
Thanks so much for investigating this, that will definitely be helpful when trying to get this fixed!
Same wish here - my environment variable is
GIT_SSH=C:\Program Files\PuTTY\plink.exe
The button "Create PR" is without any feedback. Even not an error message...
Following https://poshsecurity.com/blog/using-the-openssh-client-included-in-windows-10-1809-as-your-gits-ssh-client, it is more easy:
- "Enable agent for Windows OpenSSH" in KeeAgent:
- Set environment variable
GIT_SSHtoC:/Windows/System32/OpenSSH/ssh.exe.
I did not have success with following: Configure to use Windows' ssh for this repository:
[core]
sshcommand = C:/Windows/System32/OpenSSH/ssh.exe
Same wish here - my environment variable is
GIT_SSH=C:\Program Files\PuTTY\plink.exeThe button "Create PR" is without any feedback. Even not an error message...
Same env here. I changed it to "C:\Program Files\PuTTY\plink.exe" meaning, surround it with literal quotes, make the quotes part of the value (see how @jmaerki has his ssh.exe location with quotes).
Now, the -o issue is still a problem. It can be hacked away with a pass-through script that filters out those options, but it's not ideal.
OK, so I wrote a PowerShell script and I'm using it as a workaround for me. I set GIT_SSH to pwsh -noprofile C:\Users\my-user\plinkFix.ps1 and GIT_SSH_VARIANT to plink. You may want to edit the script and set a hardcoded path to plink.exe, and you can activate the logging if something breaks to see what arguments are being received and how the script is filtering them.
The script has requirement clauses for PowerShell Core version 7, but you may be able to use the Desktop version and call powershell instead of pwsh and it will probably work anyways if you remove the clauses (first 4 lines).