Github wrong username

前端 未结 1 808
没有蜡笔的小新
没有蜡笔的小新 2021-02-03 14:20

I have setup with guthub with a previous github account on this computer called myaccount when i run this command

ssh -T git@github.com
Hi myaccount! You\'ve su         


        
1条回答
  •  天涯浪人
    2021-02-03 15:16

    GitHub recognizes you as myaccount because SSH is using a key that corresponds to a public key that has been added to the myaccount account on the GitHub website.

    If you want to switch entirely to using the sameueleast account instead of myaccount, you can do the following:

    • Login to GitHub's website as myaccount
    • Go to "Account Settings"
    • Go to "SSH Public Keys"
    • Delete your public key from that list
    • Logout
    • Login to GitHub's website as samueleast
    • Go to "Account Settings" -> "SSH Public Keys"
    • Select "Add another public key" and paste in the contents of your public key. You public key will (probably) be called id_rsa.pub or id_dsa.pub and be in your .ssh directory.

    On the other hand, if you want to be able to use either myaccount or samueleast when pushing to GitHub, you will need to create aliases for git@github.com in ~/.ssh/config, such as:

    Host github-myaccount
        User git
        Hostname github.com
        PreferredAuthentications publickey
        IdentityFile ~/.ssh/id_dsa-myaccount.pub
    
    Host github-samueleast
        User git
        Hostname github.com
        PreferredAuthentications publickey
        IdentityFile ~/.ssh/id_dsa-samueleast.pub
    

    That assumes you've generated a second SSH keypair and given them names as above. Then you need to make sure that you are using the appropriate alias in the URLs of your git remotes. For example, if you want to change your origin remote so that pushing to origin means "pushing to origin as samueleast", you could do:

     git remote set-url origin \
         git@github-samueleast:samueleast/Samuel-East-S3-Audio-Playlist-Player.git
    

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