问题
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 successfully authenticated, but GitHub does not provide shell access.
Ok but i have now setup a new github account called samaccount but i cant run this command i get this error.
git push -u origin master
i get this error
ERROR: Permission to samueleast/Samuel-East-S3-Audio-Playlist-Player.git denied to myaccount.
I dont want it to use myaccount it should be using samaccount !!!
i have followed all the steps here http://help.github.com/mac-set-up-git/ setup brand new ssh key.
and also run this command many times
git config --global user.name "samaccount"
but it still uses myaccount its sooo annoying where am i going wrong???
回答1:
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
orid_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
来源:https://stackoverflow.com/questions/8151854/github-wrong-username