SSH Key ask to enter passphrase after start-agent

I have 2 ssh key for 2 different accounts on Bitbucket.

The below is my bachrc file:

  • Why 'git ls-files' is not shown on tab completion?
  • Powershell Git Hook Exit Code
  • Docker Quickstart Terminal - fork: retry: No child processes
  • Find most recent good commit to pass to git bisect
  • Git: Preventing Commit During a Rebase
  • Capistrano deploy on windows fails with git
  • # Note: ~/.ssh/environment should not be used, as it
    #       already has a different purpose in SSH.
    # Note: Don't bother checking SSH_AGENT_PID. It's not used
    #       by SSH itself, and it might even be incorrect
    #       (for example, when using agent-forwarding over SSH).
    agent_is_running() {
        if [ "$SSH_AUTH_SOCK" ]; then
            # ssh-add returns:
            #   0 = agent running, has keys
            #   1 = agent running, no keys
            #   2 = agent not running
            ssh-add ~/.ssh/id_rsa ~/.ssh/id_rsa_2 -l >/dev/null 2>&1 || [ $? -eq 1 ]
    agent_has_keys() {
        ssh-add -l >/dev/null 2>&1
    agent_load_env() {
        . "$env" >/dev/null
    agent_start() {
        (umask 077; ssh-agent >"$env")
        . "$env" >/dev/null
    if ! agent_is_running; then
    # if your keys are not stored in ~/.ssh/id_rsa or ~/.ssh/id_dsa, you'll need
    # to paste the proper path after ssh-add
    if ! agent_is_running; then
        ssh-add ~/.ssh/id_rsa ~/.ssh/id_rsa_2
    elif ! agent_has_keys; then
        ssh-add ~/.ssh/id_rsa ~/.ssh/id_rsa_2
    unset env
    agent_stop() {
        if [ ${SSH_AGENT_PID+1} == 1 ]; then
            ssh-add -D
            ssh-agent -k > /dev/null 2>&1
            unset SSH_AGENT_PID
            unset SSH_AUTH_SOCK

    Why do I call agent_stop?

    That’s for testing. I figured out that when agent_stop is called, all ssh keys are removed from agent and then when opened git bash again, the agent automatically adds ssh keys.

    But only id_rsa doesn’t prompt passphrase, the id_rsa_2 prompt everytime.

    P/S: The public key of id_rsa_2 is added on Bitbucket.

    What am I missing for this?

  • Sharing Models between two Rails Projects - using git submodules?
  • Why is git looking in the wrong directory for the git installation? (OS X)
  • How do I retrieve a git repository from Heroku?
  • How do I go back to previous Git Commit?
  • Git - transferring all commits to another branch and creating a new master
  • Azure ASP.Net MVC database deployment best practice
  • 2 Solutions collect form web for “SSH Key ask to enter passphrase after start-agent”

    Note: if you generate an ssh key without passphrase

    ssh-keygen -t rsa -f ".ssh/mykey" -C "key for xxx acess" -q -P ""

    Then you don’t need ssh-agent at all

    When you run ssh-keygen, there is one step ask you whether you need a
    passphrase, you can click enter to skip or enter a passphrase, if my
    memory serve me correctly

    From gzh

    Git Baby is a git and github fan, let's start git clone.