SSH key switching for multiple github accounts

Source: Internet
Author: User

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

$ 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

$ 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:

Host github.com    HostName github.com    preferredauthentications publickey    identityfile ~/.ssh/id_rsahost 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

The #my.github.com in the URL in the #更改 [remote origin] item corresponds to the Host[remote "origin" configured above]url = [email protected]:itmyline/blog.git
or modify the remote when you commit in Git bash
$ git remote rm origin$ git remote add origin [email protected]:itmyline/blog.git

2, the clone warehouse corresponding configuration Host Account
#my. github.com corresponds to an account git clone [email protected]:username/repo.git


Itmyhome



SSH key switching for multiple github accounts

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.