You can add multiple SSH keys in the background of GitHub, but the same SSH keys can only be added to an account ("Key is already" when added). The reason is easy to think that SSH public key use is equivalent to the user name password, it is not possible to two different accounts with the same user name password. To add a public key to multiple github accounts, generate multiple SSH keys locally, one for each GitHub account, and a different SSH keys. The steps are as follows:
1. Generate a new SSH KEY
- [Email protected] : ~$ ssh-keygen -t RSA -C ' [email protected] '
- Generating public/private RSA key pair.
- Enter file in which to save the key (~/. SSH/id_rsa): ~/. SSH/id_rsa2 #这里输入一个新的ssh key file name
- Enter Passphrase (empty for no passphrase):
- Enter same Passphrase again:
- Your identification have been saved in ~/. SSH/id_rsa2.
- Your public Key had been saved in ~/. SSH/id_rsa2. Pub.
- The key fingerprint is:
- 3a:01: 17:b3:f9 :26:5b: 53:b3:69 :be:71: a8:66:f6 :96 [Email protected]. Me
- The key' s Randomart image is:
- +--[RSA 2048]----+
- | o |
- | = |
- | . + O |
- | . . . + |
- | o S + |
- | B +. |
- | + .+ + |
- | . E.. + |
- | +.oo |
- +-----------------+
- [Email protected]:~$ ssh-add ~/.ssh/id_rsa2
- Identity added: ~/.SSH/ID_RSA2 (~/.SSH/ID_RSA2)
~/.SSH/ID_RSA2 for the new SSH keys file name, according to the actual situation, to ensure that each time is different.
2. Open the newly generated ~/.ssh/id_rsa2.pub file and add the contents to the GitHub backend.
3. Open the ~/.ssh/config file (not created) and add a host:
- #建一个github别名, the new account is cloned and updated with this alias
- Host github2
- HostName GitHub. COM
- User git
- Identityfile ~/.ssh/id_rsa2. Pub
4. Replace the [email protected] in the GitHub SSH warehouse address with the new host alias.
If the original address is: [email protected]:freehost/mail.git, after the replacement should be: Github2:freehost/mail.git
If you are creating a new warehouse, use the replacement URL clone directly. If you have cloned using the original address, you can use the command to modify:
- Git remote set-URL Origin github2:freehost/mail. git
original articles, reproduced please specify: reproduced from www.webmaster.me
This article link address: Add SSH Public key to multiple accounts on GitHub
Add an SSH public key to multiple accounts on GitHub