Github wrong username

主宰稳场 提交于 2019-12-03 03:57:01

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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!