Github multiple accounts one computer always sees one account

前端 未结 4 1190
广开言路
广开言路 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:55
    debug2: key:  
    debug2: key:  
    debug2: key: /home//.ssh/identity ((nil))
    debug2: key: /home//.ssh/id_rsa ()
    debug2: key: /home//.ssh/id_dsa ((nil))
    

    That looks terribly suspicious. Why is your home directory just /home/? If more than one user has the same home directory, then I'm not surprised ssh finds the same key for both users. Check the results of

    echo $HOME
    

    while logged in as each user. They should point to different directories.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-16 04:58

    To state my assumptions for this answer, it sounds from the question title as if what you really want to do is to be able to push to GitHub being identified as different GitHub users.

    If that's the case, you shouldn't create multiple users on your system just in order to push as different GitHub users over SSH. The right way to do this is to set up two aliases for github.com in ~/.ssh/config that specify different identity files, as described here. For example, you might have in your ~/.ssh/config the following:

    Host github-act1
      HostName github.com
      User git
      IdentityFile /home/whoever/.ssh/id_rsa.act1
    
    Host github-act2
      HostName github.com
      User git
      IdentityFile /home/whoever/.ssh/id_dsa.act2
    

    Then you can add two remotes to your repository:

    git add remote act1 git@github-act1:whoever/whatever.git
    git add remote act2 git@github-act1:whoever/whatever.git
    

    Then if you want to push as one user you can do:

    git push act1 master
    

    ... or as the second account:

    git push act2 master
    
    0 讨论(0)
  • 2020-12-16 05:10

    Take a look at the permissions to the .git folder and it's contents. Confirm which SSH key is being passed to github with ssh github.com -vvvv.

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