Github multiple accounts, the local configuration ssh-key

Due to the need to apply for a number of githubaccounts, but all operate on the same computer, the original account be only one sshoperation, push did not encounter any problems, there are now multiple accounts, and when he pushed a bit stupid to force, the following is based on the information available to multiple accounts, configure the local ssh-keyoperation of the process.

Single account ssh-key configuration View article: GitHub setting adds ssh

A locally generated different accounts of secret key information

ssh-keygen -t rsa -C "[email protected]"  #账号1

ssh-keygen -t rsa -C "[email protected]" #账号2

Mailbox replace their github account binding mailbox.

After running the above command will let you enter a file name for saving the generated SSH key code, such as:

CopyGenerating public/private rsa key pair.
# Enter file in which to save the key (/c/Users/you/.ssh/id_rsa): [Press enter]

If there is only one account, you can save a default.

When a plurality of accounts may enter the file name own custom later, it used to distinguish between different accounts generated secret key.

After entering the file name, press Enter to continue down will prompt you to enter a password, you can not directly enter a password.

Multiple accounts are the same operation, after the operation, will be in ~/.sshgenerating a plurality of keys directory.

Second, the public key is added to different github account

Respectively log onto their github account, then the generated public key (.pub file ending) is added to the next corresponding account:

Settings —> SSH and GPG keys

Third, the configuration file config

When not need to configure a single account, the default, to be configured as a plurality of accounts.

Check whether there is a config file at ~ / .ssh file does not exist, then create a new, fill in the corresponding configuration information:

Host coder.github.com  // 别名
HostName github.com // 服务器地址
User javage // github用户名
IdentityFile  ~/.ssh/coder // 对应的秘钥地址

Host tester.github.com
HostName github.com
User tester
IdentityFile  ~/.ssh/tester

Fourth, add key information to the ssh-agent

Because the default id_rsa generated by default only read in order for him to be able to read the secret key information after the modification, you need to add to the ssh-agent in:

ssh-add ~/.ssh/coder // 对应的秘钥文件

ssh-add ~/.ssh/tester

If execution of the command prompt:

Could not open a connection to your authentication agent.

Need to be performed under the following command:

ssh-agent bash

Then proceed to the previous command.

Fifth, the test is configured correctly

ssh -T [email protected]

ssh -T [email protected]

As used herein, the alias access, git may request through the information corresponding to the account configuration config.

Request success tips:

$ ssh -T [email protected]
Hi javaGe! You've successfully authenticated, but GitHub does not provide shell access.

$ ssh -T [email protected]
Hi testerggf! You've successfully authenticated, but GitHub does not provide shell access.

Cloning Project:

$ git clone [email protected]:testerggf/studygit.git
Cloning into 'studygit'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
Receiving objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0

Guess you like

Origin www.cnblogs.com/tester-ggf/p/12234329.html