Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get only remote git operations to trigger a ssh-add event for ssh-agent?
    primarykey
    data
    text
    <p>I recently asked a <a href="https://askubuntu.com/questions/36255/why-wont-ssh-agent-save-my-unencrypted-key-for-later-use">question on AskUbuntu</a> about getting ssh-agent to automatically save my passphrase protected key for later re-use without having to re-enter the passphrase during bash login (non-GUI/Gnome). I got a nice bash script in response, but unfortunately it is triggered to ask for the passphrase no matter the git operation. I only want to be prompted if they key is not already in ssh-agent and a remote git operation is being performed.</p> <p>This is due to the fact that I use <code>$(__git_ps1 "[%s]")</code> in my bash prompt to display the git branch of the current working directory (<code>pwd</code>). So when I ssh into the machine it immediately asks me for the keys passphrase before it can render the bash prompt!</p> <p>The current script from <a href="https://askubuntu.com/questions/36255/why-wont-ssh-agent-save-my-unencrypted-key-for-later-use/36302#36302">the answer to my question on AskUbuntu</a> looks like:</p> <p>In <code>~/.bash_profile</code>:</p> <pre><code># File: ~/.bash_profile # source ~/.profile, if available if [[ -r ~/.profile ]]; then . ~/.profile fi # start agent and set environment variables, if needed agent_started=0 if ! env | grep -q SSH_AGENT_PID &gt;/dev/null; then echo "Starting ssh agent" eval $(ssh-agent -s) agent_started=1 fi # ssh become a function, adding identity to agent when needed ssh() { if ! ssh-add -l &gt;/dev/null 2&gt;-; then ssh-add ~/.ssh/id_dsa fi /usr/bin/ssh "$@" } export -f ssh # another example: git git() { if ! ssh-add -l &gt;/dev/null 2&gt;-; then ssh-add ~/.ssh/id_dsa fi /usr/bin/git "$@" } export -f git </code></pre> <p>So as you can see the git function is triggered on every git operation.</p> <p>I had thought that git would use <code>ssh</code> to make the connection, but it doesn't appear to trigger the <code>ssh()</code> function in the above script. How does git perform its ssh operations? Does it access /usr/bin/ssh directly rather than relying on the bash path?</p> <p>Have you got a better way of doing this or a nice workaround for the current script?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload