Access Github from multiple Github accounts

Access Github from multiple Github accounts

background

What if I want to use two Github accounts on this computer at the same time? The SSH public key on your host can only identify one account. If you need to use another git account to access the warehouse, you need to create a new SSH public key.

Github does not allow the use of the same SSH Key on multiple accounts. When you set it up, a "Key is already in use" prompt will appear.

step

When using ssh-keygen again to generate a new key, the previous one will be overwritten, so we need to specify the new generated path :

ssh-keygen -t rsa -C "[email protected]"

When we use the git command, only the key ~/.ssh/id_rsa will be used by default. So how can we use this newly created key? This can be solved using config files.

Create or edit

vi ~/.ssh/config
# Default GitHub SSH configuration
Host github.com
   HostName github.com
   IdentityFile ~/.ssh/id_rsa

# Personal repo SSH configuration
Host github.com_personal
   HostName github.com
   IdentityFile ~/.ssh/id_rsa_personal
   User personal_username

In the terminal, clone the second GitHub account using the alias:
git clone [email protected]_personal:personal_username/repo_name.git
where "personal_username" is the username of your second GitHub account, "repo_name" is the name of the repository you want to clone.

Personal testing is available! It's equivalent to configuring an alias. When git operates, git knows that you want to use the ssh public key of the alias.

reference

[Recommended] How to configure SSH to manage multiple Git repositories and multiple Github accounts.
Reference URL: https://baijiahao.baidu.com/s?id=1769812225308358655&wfr=spider&for=pc

Guess you like

Origin blog.csdn.net/inthat/article/details/132250484