Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git push using ssh-agent in bash but not gui

Tags:

Using git for windows (git-scm.com) and a script, i can get Bash to stop asking for the passphrase but i can not seem to remove the passphrase prompt from git GUI.

The url to the remote is using the ssh link (see below), so im pretty sure this is not the problem. But i am not an expert in git nor SSH..

[email protected]:repo

The SSH keys (ED25519) have been created with a passphrase provided and the public key was added to the hosting account. The SSH keys are stored in the typical location C:\Users\<user>\.ssh\id_ed25519. When clicking Help->Show SSH Key in the GUI, it shows my ssh key that is being used. The ssh-agent is running in the background and the ssh key has been added to the ssh-agent via the setup below.

Setting up the ssh-agent i had used the code provided here (copied and pasted below for reference) to create the .bashrc file under the C:\Users\<user> path. Everything seems to be running as expected under the bash prompt but not the Git GUI.

env=~/.ssh/agent.env

agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }

agent_start () {
    (umask 077; ssh-agent >| "$env")
    . "$env" >| /dev/null ; }

agent_load_env

# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)

if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
    agent_start
    ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
    ssh-add
fi

unset env

To me, it seems like the Git GUI is not using the ssh-agent when performing an push, fetch, or any other related remote feature. Is there a step i missed in setting up the ssh-agent, .bashrc script, and or the GUI to finish removing the passphrase prompt? or is there something else going on?

Any and all help is much appreciated, Thanks in advance

like image 618
Mr.Invisible Avatar asked Jun 14 '19 20:06

Mr.Invisible


2 Answers

.bashrc runs when you start Git Bash. This affects the bash environment only but doesn't do anything for Windows as a whole. When you run the GUI, none of the setup in .bashrc is in effect. I use the Git integration in IntelliJ on my Windows laptop and still haven't figured out how to use my SSH keys with it. I currently open Git Bash to pull, push, or anything else that interacts with a remote.

like image 65
Code-Apprentice Avatar answered Sep 29 '22 07:09

Code-Apprentice


Viewing a Guide i found here, this led me to search things differently. Ultimately telling me to use Putty and its ssh agent to manage passwords for me.

Eventually stumbled upon this post in which they talk about how to get git to use putty's ssh agent. This simply came down to me putting GIT_SSH into the environment variables pointing to plink.exe, found within putty's installation folder.

When using this method, it does present an error that i'm not sure is just my machine/installation or if this effects everyone. The problem was solved here in this post by opening putty and ssh into the host to generate the cache this way. Because there is already a posting on this, i'll refrain from going any further into why git could not do this step for me.

Also note from my above question, i was using a .bashrc script to automatically launch keys into the OpenSSH ssh-agent upon opening git bash. Because of this putty approach, this script and all the relevant files were removed. This short list of removed files were the agent.env that the script creates, the .bashrc that held the script, and also the .pash_profile that was created.

Once done, both git bash and git gui were successfully using putty agent and can be used anyway i like. I can even launch git gui from the context menu and have it recognize the ssh keys and no longer prompt for a passphrases.

like image 41
Mr.Invisible Avatar answered Sep 29 '22 07:09

Mr.Invisible