Git keeps asking me for my ssh key passphrase

前端 未结 14 1880
长情又很酷
长情又很酷 2020-11-27 09:07

I created keys as instructed in the github tutorial, registered them with github, and tried using ssh-agent explicitly — yet git continues to ask me for my passphrase every

相关标签:
14条回答
  • 2020-11-27 09:25

    What worked for me on Windows was (I had cloned code from a repo 1st):

    eval $(ssh-agent)
    ssh-add 
    git pull 
    

    at which time it asked me one last time for my passphrase

    Credits: the solution was taken from https://unix.stackexchange.com/questions/12195/how-to-avoid-being-asked-passphrase-each-time-i-push-to-bitbucket

    0 讨论(0)
  • 2020-11-27 09:25

    It sounds like you may be having trouble with SSH-Agent itself. I would try troubleshooting that.

    1) Did you do ssh-add to add your key to SSH?

    2) Are you closing the terminal window between uses, because if you close the window you will have to enter the password again when you reopen it.

    0 讨论(0)
  • 2020-11-27 09:27

    I would try the following:

    1. Start GitBash
    2. Edit your ~/.bashrc file
    3. Add the following lines to the file

    SSH_ENV=$HOME/.ssh/environment
    
    # start the ssh-agent
    function start_agent {
        echo "Initializing new SSH agent..."
        # spawn ssh-agent
        /usr/bin/ssh-agent | sed 's/^echo/#echo/' > ${SSH_ENV}
        echo succeeded
        chmod 600 ${SSH_ENV}
        . ${SSH_ENV} > /dev/null
        /usr/bin/ssh-add
    }
    
    if [ -f "${SSH_ENV}" ]; then
         . ${SSH_ENV} > /dev/null
         ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
            start_agent;
        }
    else
        start_agent;
    fi
    
    1. Save and close the file
    2. Close GitBash
    3. Reopen GitBash
    4. Enter your passphrase
    0 讨论(0)
  • 2020-11-27 09:30

    Once you have started the SSH agent with:

    eval $(ssh-agent)
    
    1. You have to add your private key to it:

      ssh-add
      

      This will ask you your passphrase just once, and then you should be allowed to push, provided that you uploaded the public key to Github.

    2. To save key permanently on macOS:

      ssh-add -K  
      

      This will persist it after you close and re-open it by storing it in user's keychain.

    0 讨论(0)
  • 2020-11-27 09:31

    If you've tried ssh-add and you're still prompted to enter your passphrase then try using ssh-add -K. This adds your passphrase to your keychain.

    Update: if you're using macOS Sierra then you likely need to do another step as the above might no longer work. Add the following to your ~/.ssh/config:

    Host *
      UseKeychain yes
    
    0 讨论(0)
  • 2020-11-27 09:34

    Try adding this to your ~/.ssh/config:

    Host *
       AddKeysToAgent yes
       UseKeychain yes
       IdentityFile ~/.ssh/id_rsa
    

    ... assuming your private key is named id_rsa

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