Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

The back story -- I've been using Git on this computer (Windows XP) for about 8 months with no problem. Suddenly, last week, it is no longer asking me for my username and password when I start Git up.

It is asking every time I try to touch my remote branches, and considering I have a passphrase rather than a password it is really annoying.

I am using the code from GitHub in my .profile file:

SSH_ENV="$HOME/.ssh/environment"

# start the ssh-agent
function start_agent {
    echo "Initializing new SSH agent..."
    # spawn ssh-agent
    ssh-agent | sed 's/^echo/#echo/' > "$SSH_ENV"
    echo succeeded
    chmod 600 "$SSH_ENV"
    . "$SSH_ENV" > /dev/null
    ssh-add
}

# test for identities
function test_identities {
    # test whether standard identities have been added to the agent already
    ssh-add -l | grep "The agent has no identities" > /dev/null
    if [ $? -eq 0 ]; then
        ssh-add
        # $SSH_AUTH_SOCK broken so we start a new proper agent
        if [ $? -eq 2 ];then
            start_agent
        fi
    fi
}

# check for running ssh-agent with proper $SSH_AGENT_PID
if [ -n "$SSH_AGENT_PID" ]; then
    ps -ef | grep "$SSH_AGENT_PID" | grep ssh-agent > /dev/null
    if [ $? -eq 0 ]; then
  test_identities
    fi
# if $SSH_AGENT_PID is not properly set, we might be able to load one from
# $SSH_ENV
else
    if [ -f "$SSH_ENV" ]; then
  . "$SSH_ENV" > /dev/null
    fi
    ps -ef | grep "$SSH_AGENT_PID" | grep ssh-agent > /dev/null
    if [ $? -eq 0 ]; then
        test_identities
    else
        start_agent
    fi
fi

The line that is catching it is:

if [ -n "$SSH_AGENT_PID" ]; then

It thinks it's a valid entry. Needless to say, I've restarted and relogged onto my computer in many different ways, always the same. I've echoed out the process ID and it isn't a running process on my computer (per Task Manager).

I am have upgraded my Git (hoping it would fix the problem) and I am now running version 1.7.11-preview20120620

Any help would be greatly appreciated.

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

How about simplifying it a bit?

agent_running() {
    [ "$SSH_AUTH_SOCK" ] && { ssh-add -l >/dev/null 2>&1 || [ $? -eq 1 ]; }
}

env=~/.ssh/agent.env

if ! agent_running && [ -s "$env" ]; then
    . "$env" >/dev/null
fi

if ! agent_running; then
    ssh-agent >"$env"
    . "$env" >/dev/null
    ssh-add
fi

unset env
share|improve this answer
    
Nice! Works like a charm! –  Kerry Jun 26 '12 at 19:46
    
Excellent! This Works on win XP! Totally different to the one in this tute, obviously the tute has wrong code for windows: the $HOME has spaces in it and this isn't allowed and can't be manually excaped (I tried). –  user233105 Jun 23 '13 at 4:17
    
@Bezz: It can certainly be quoted: . "$HOME/.ssh/env" or . "$SSH_ENV" –  grawity Jun 23 '13 at 13:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.