Original address: Http://blog.csdn.net/itmyhome1990/article/details/42643233?utm_source=tuicool&utm_medium=referral
There is an SSH key on a computer that submits the code on GitHub for other reasons
You might be able to submit it to a different github on a single computer.
If you have an SSH key on your computer, if you have a default one, generate the second one directly.
One, build and add the first SSH key
[Plain]View PlainCopy
- $ ssh-keygen-t rsa-c "[Email protected]"
Execute the command in GIT bash all the way to the return, generate Id_rsa and id_rsa.pub two files in the ~/.ssh/directory
Open content in id_rsa.pub with a text editor and add SSH Keys to GitHub
Do not understand, please refer to GitHub create SSH Keys
Ii. generate and add a second SSH key
[Plain]View PlainCopy
- $ ssh-keygen-t rsa-c "[Email protected]"
Don't go all the way this time, give this file a name or the default is to overwrite the first generated
If the name is my, the directory structure is as follows:
If the resulting second SSH key is not in the. ssh/, you can move to this directory
The contents of the config file created under. ssh/are as follows:
[Plain]View PlainCopy
- Host github.com
- HostName github.com
- Preferredauthentications PublicKey
- Identityfile ~/.ssh/id_rsa
- Host my.github.com
- HostName github.com
- Preferredauthentications PublicKey
- Identityfile ~/.ssh/my
The host name is optional and will be used next.
Iv. test configuration is correct
If Hi xxx! appears You ' ve successfully authenticated the connection is successful
Different approaches are now given in the following scenarios:
1. Local has been created or has been clone to Local:
There are two workarounds:
Open a. git/config file
[Plain]View PlainCopy
- #更改 in the URL in the [Remote origin] Item
- #my. github.com corresponds to the host configured above
- [remote "origin"]
- url = [email protected]:itmyline/blog.git
or modify the remote when you commit in Git bash
[Plain]View PlainCopy
- $ git Remote RM origin
- $ git Remote add origin [email protected]:itmyline/blog.git
2, the clone warehouse corresponding configuration Host Account
[Plain]View PlainCopy
- #my. github.com corresponds to an account
- git clone [email protected]:username/repo.git
SSH key switching for multiple github accounts