TortoiseGit with openssh key not authenticating using ssh-agent

前端 未结 8 1030
暗喜
暗喜 2020-11-30 01:03

I\'m setting up a git environment on Windows XP (msysGit 1.7.11, TortoiseGit 1.7.14) and trying to achieve following points :

  • ssh connection on a port differ
相关标签:
8条回答
  • 2020-11-30 01:34

    1) Cygwin

    Use approach described in the following article: https://help.github.com/articles/working-with-ssh-key-passphrases

    Password will be asked only once on the cygwin session startup. !!! Before exiting cygwin session don't forget to kill ssh-agent process (use ps for find process PID and kill -9).

    We are using separate approach for cygwin, because cygwin by some reason doesn't see processes started externally in windows environment.

    2, 3) MsysGit, TortoiseGit

    Useful link: http://dogbiscuit.org/mdub/weblog/Tech/WindowsSshAgent

    Install MsysGit. Install TortoiseGit (check openssh instead of plink during installation). !!! Check systems variables. If there is GIT_SSH variable present - remove it.

    Go to TortoiseGit->Settings->General

    Set Git exe Path to /bin Set External dll path to /mingw/bin

    Go to TortoiseGit->Settings->Network Set SSH Client property to /bin/ssh.exe

    Define system variable SSH_AUTH_SOCKS=C:\temp.ssh-socket

    Start cmd.exe and execute following commands(since we installed MsysGit all following commands are accessible in cmd - /bin is added to system PATH variable):

    # following command is required to execute for avoiding Address already bind message when ssh-agen is not started yet but .ssh-socket exists after previous agent session
    rm "%SSH_AUTH_SOCK%"
    
    # Starting ssh-agent
    ssh-agent -a "%SSH_AUTH_SOCK%"
    
    # Adding our openssh key
    ssh-add "%USERPROFILE%\.ssh\id_rsa"
    
    # Type password for your key
    

    That's it. From that moment you can execute git push, git pull from TortoiseGit and MsysGit without prompting passphrase.

    When ssh-agent is no longer required you can kill it through windows task manager.

    0 讨论(0)
  • 2020-11-30 01:37

    Since the explanations here are a bit outdated, I decided to post my solution.

    I am using Git Bash and TortoiseGit 2.8.0 in Windows 10, which are common nowadays.

    I set ssh.exe as SSH client in Settings->Network as explained in previous posts.

    I created a script with the following commands, as explained in a previous comment. You might also want to set a HOME environment variable, in case your system does not do it automatically. Assuming your home is in drive H:\ you can add the following lines:

    SETX HOME /h
    CALL "C:\Program Files\Git\cmd\start-ssh-agent.cmd"
    SETX SSH_AUTH_SOCK "%SSH_AUTH_SOCK%"
    SETX SSH_AGENT_PID "%SSH_AGENT_PID%"
    

    I added the script using Win logo+R shell:startup to the startup folder. Alternatively, you can add the script to the registry to guarantee that it runs before other processes:

    HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
    

    Make sure to type exit to close the console and allow for the variable to be set for future processes.

    0 讨论(0)
  • 2020-11-30 01:39

    I first installed TortoiseGit with Plink and using Pageant to load ssh private key. The automatic authentication (Pageant) worked but setup was a fail as TortoiseGit don't recognize git repos url formatted as gitolite@gitbox/repo.git.

    I finally found a workaround which consist to create a PuTTY session with the same name that the ssh alias (ie gitbox in the question).
    This way I can clone as git clone gitbox/monrepo in the CLI and the origin syntax is correctly handled by TortoiseGit.

    0 讨论(0)
  • 2020-11-30 01:43

    No tweaks needed.

    Just make TortoiseGit point to the same ssh client used by git itself, see the screenshot:

    This should be C:\Program Files\Git\usr\bin\ssh.exe in latest version of Git as mentioned by Aleksey Kontsevich in the comments.

    0 讨论(0)
  • 2020-11-30 01:43

    None of the above answers worked for me.

    I created this batch file to solve the problem.

    CALL "C:\Program Files\Git\cmd\start-ssh-agent.cmd"
    SETX SSH_AUTH_SOCK "%SSH_AUTH_SOCK%"
    SETX SSH_AGENT_PID "%SSH_AGENT_PID%"
    

    Run this once, and enter your passphrase.

    Then you can use tortoisegit with openssh without having to enter your passphrase for every operation.

    0 讨论(0)
  • 2020-11-30 01:43

    Make sure to launch your TortoiseGit in an environment where HOME is defined, and reference the parent directory of .ssh.
    This is important since, on Windows, HOME isn't defined by default.

    See as an example: "Auth fails on Windows XP with git and tortoisegit".
    (Other possible sources: "How to I tell Git for Windows where to find my private RSA key?")

    0 讨论(0)
提交回复
热议问题