Git keeps asking me for my ssh key passphrase

前端 未结 14 1913
长情又很酷
长情又很酷 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:11

    This has been happening to me after restarts since upgrading from OS X El Capitan (10.11) to macOS Sierra (10.12). The ssh-add solution worked temporarily but would not persist across another restart.

    The permanent solution was to edit (or create) ~/.ssh/config and enable the UseKeychain option.

    Host *
        UseKeychain yes
    

    Related: macOS keeps asking my ssh passphrase since I updated to Sierra

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

    I try different solutions but nothing help. But this steps (My GitBash SSH environment always asks for my passphrase, what can I do?) from Bitbucket.com seams works well :

    The idea is:

    1. you create ~/.bashrc file

    2. add follow script:

      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
      
    3. re-run Bash

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

    on mac, if your ssh key need passphrase everytime and you want to skip it, then you can try below, it works fine for me

    1. eval "$(ssh-agent -s)"
    2. ssh-add -K .ssh/id_rsa
    3. add this default ssh configuration works for me

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

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

    Another possible solution that is not mentioned above is to check your remote with the following command:

    git remote -v
    

    If the remote does not start with git but starts with https you might want to change it to git by following the example below.

    git remote -v // origin is https://github.com/user/myrepo.git
    git remote set-url origin git@github.com:user/myrepo.git
    git remote -v // check if remote is changed
    
    0 讨论(0)
  • 2020-11-27 09:22

    For Windows or Linux users, a possible solution is described on GitHub Docs, which I report below for your convenience.

    You can run ssh-agent automatically when you open bash or Git shell. Copy the following lines and paste them into your ~/.profile or ~/.bashrc file:

    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
    

    If your private key is not stored in one of the default locations (like ~/.ssh/id_rsa), you'll need to tell your SSH authentication agent where to find it. To add your key to ssh-agent, type ssh-add ~/path/to/my_key.

    Now, when you first run Git Bash, you are prompted for your passphrase. The ssh-agent process will continue to run until you log out, shut down your computer, or kill the process.

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

    If the above solutions are not working for me, one thing to check is that you actually have the public key too (typically id_rsa.pub). It is unusual not to, but that was the cause for me.

    To create your public key from your private key:

    ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub
    
    0 讨论(0)
提交回复
热议问题