Github multiple accounts one computer always sees one account

前端 未结 4 1191
广开言路
广开言路 2020-12-16 04:15

This is probably not a dup; I have read through many similar problems on StackOverflow but not this issue.

I am trying to use multiple git accounts on Ubuntu Linux a

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-16 04:58

    This happens because ssh-agent caches the ssh key (you can even remove the file and it will still allow ssh to connect successfully until the cache is cleared) and will prioritise the cached keys even over the ones specified via IdentityFile. You can see which files are cached by running:

    ssh-add -l
    

    You can force ssh-agent to ignore the cache by including IdentitiesOnly "yes" in the .ssh/config for each connection:

    Host github
      HostName github.com
      User git
      IdentityFile ~/.ssh/id_rsa
      IdentitiesOnly yes
    
    Host github-work
      HostName github.com
      User git
      IdentityFile ~/.ssh/id_dsa_work
      IdentitiesOnly yes
    

    More information here: http://sealedabstract.com/code/github-ssh-with-multiple-identities-the-slightly-more-definitive-guide/

    It took me quite a while to discover this too, hope it helps someone.

提交回复
热议问题