preface

Before configuring multiple local ssh-keys, initialize GIt environment first.

Can refer to: www.cnblogs.com/poloyy/p/12…

Just do the first two steps

 

Two Ssh-keys are generated locally

ssh-keygen -t rsa -C "[email protected]" -f ~/.ssh/polo_rsa
ssh-keygen -t rsa -C "[email protected]" -f ~/.ssh/polo1_rsa
Copy the code

 

Making add SSH key

Add the two generated public keys to Github; You can add one public key to account A and the other to account B, so that the code for different repositories can be submitted locally at the same time

(how to add SSH key – see www.cnblogs.com/poloyy/p/12…).

 

Generate a configuration file with multiple local public keys

Generate the config file in the local C:\Users\ username \.ssh folder without the suffix and fill in the following

# add config file:  # home Host polo.github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/polo_rsa User polo # work Host polo1.github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/polo1_rsa User polo1 # config file parameter # Host: can be considered as a pattern that you want to identify, configure the corresponding Host name and SSH file # HostName: to log in to the Host name # User: # IdentityFile: specifies the IdentityFile path corresponding to the User aboveCopy the code

Pay attention to the point

  • Red fonts need to be changed according to their own situation
  • The file name after IdentityFile is the name of the public key you generated, as shown below

 

Verify success

Enter the following command

ssh -T git@{Host}
ssh -T git@{Host}
Copy the code

“Host” = “config”; “config” = “config”; “Host” = “config”

 

Clone different warehouse codes

To local a single public key, run the git clone command as follows

[email protected]: user name/project name.gitCopy the code

When multiple public keys exist and the clone project is local, you need to modify the command

[email protected]: username 1/ project name 1. Git [email protected]: username 2/ project name 2Copy the code

This way you can clone different items from different accounts to local