SSH key switching for multiple GitHub accounts
There is an ssh key on one computer and code is submitted on github. for other reasons, you may submit code to different github on one computer. What should you do...
Assume that there is no ssh key on your computer. If there is one by default, generate the second
1. Generate and add the first ssh key
$ Ssh-keygen-t rsa-C "youremail@xxx.com" run the command in Git Bash and press enter all the way ~ The id_rsa and id_rsa.pub files are generated under the/. ssh/directory.
Open the content in id_rsa.pub in a text editor and add SSH Keys to Github.
For more information, see create an SSH Keys on GitHub.
Ii. Generate and add the second ssh key
$ Ssh-keygen-t rsa-C "youremail@xxx.com" don't press enter this time, give this file a name or else it will overwrite the first generated
If the name is my, the directory structure is as follows:
If the second generated ssh key is not in. ssh/, you can move it to this directory.
3. Create a config file under. ssh/as follows:
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 random and will be used later.
Iv. test whether the configuration is correct
If Hi xxx appears! You 've successfully authenticated indicates that the connection is successful.
Different methods are provided for the following situations:
1. The local file has been created or cloned to the local file:
There are two solutions:
Open the. git/config file
# Modify
# My.github.com corresponds to the host configured above
[Remote "origin"]
Url = git@my.github.com: Modify remote
$ Git remote rm origin
$ Git remote add origin git@my.github.com: account corresponding to host configuration when itmyline/blog. git2, clone Repository
# My.github.com corresponds to an account
Git clone git@my.github.com: username/repo. git Author: itmyhome
GitHub Tutorials:
Create a personal technical blog via GitHub
GitHub tutorials
Git tag management details
Git branch management
Git remote repository details
Git local Repository (Repository) Details
Git server setup and Client installation
Git Overview
Share practical GitHub tutorials
GitHub details: click here
GitHub: click here
This article permanently updates the link address: