SSH key switching for multiple GitHub accounts

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.