Introduction:
It has been a while since I entered the company, but the SSH KEY used on Github was not reconfigured when I entered the company. As a result, the name of the submitter in the VCS log of the project on Github was inconsistent with that of the Github account. So the process of configuring two SSH keys to separate work from personal Github was complicated by a configuration error and not getting the gist of the configuration sample provided by the reference blogger. The following describes the configuration process.
start
Before the configuration, you need to make preparations. Right-click the desktop or any folder, click Git Bash Here, and run the following command to query the current Git configuration information
git config --global --list
Copy the code
If user.name and user.email have values, you are advised to run the following command to unset them
git config --global --unset user.name
git config --global --unset user.email
Copy the code
After resetting the global user name and email address, run the following command to go to the. SSH directory (which is in the home directory by default)
cd ~/.ssh
Copy the code
You can use
ls -all
Copy the code
Command to check whether the directory with the configuration before the key pair and config or host file, because the author deleted key pair when configured, so the process is based on removing all of the key to the operation of the after, if you don’t want to delete the original key, can compare the process, and to modify the configuration steps.
Making configuration
After the preceding preparations are complete, the process for configuring an SSH KEY begins.
1, generate Github SSH KEY
In the bash window, run the following command to generate github’s SSH key pair
ssh-keygen -t rsa -f ~/.ssh/fileName_id_rsa -C "[email protected]"
Copy the code
SSH after -f indicates the path where the key pair is generated. FileName_id_rsa indicates the name of the key file, which can be changed by yourself. After the preceding command is executed, press Enter (no password is set by default). The key pair is generated after the command is executed.
Check whether the file is successfully generated
2. Add the newly generated SSH KEY on Github
After the key pair is successfully generated, run the following command to print the public key
cat ./fileName_rsa_id.pub
Copy the code
Enter Github and click Setting -> SSH and GPG keys -> New SSH key
You can enter any field in the Title field on the page, paste the copied public Key into the Key text box, and click Add SSH Key to complete the configuration.
Gerrit configuration
The configuration process of Gerrit is almost the same as that of Github. After generating SSH KEY pairs, configure the public keys on the Gerrit website.
1. Generate the Gerrit key pair
In the bash window, run the following command to generate github’s SSH key pair
ssh-keygen -t rsa -f ~/.ssh/gerritFileName_id_rsa -C "[email protected]"
Copy the code
SSH after -f indicates the path where the key pair is generated. GerritFileName_id_rsa indicates the name of the key file, which can be changed by yourself. After the preceding command is executed, press Enter (no password is set by default). The key pair is generated after the command is executed.
Check whether the file is successfully generated
2. Add the newly generated SSH KEY on Github
After the key pair is successfully generated, run the following command to print the public key
cat ./fileName_rsa_id.pub
Copy the code
Go to your company’s Gerrit web site and click Setting in the upper right corner of the user name menu
Then click SSH Public Keys -> Add from the left menu
Important! Config File configuration
After the Github/Gerrit key pair is generated, you need to create a config file in the ~/. SSH directory. Git will use the configuration in this file to determine which key to use for the SSH link.
Run the vi config command to create a config file in the ~/. SSH directory and press I to edit the content. The following provides a template:
# github
Host github.com
HostName github.com
User githubUsername
IdentityFile ~/.ssh/github_id_rsa
PreferredAuthentications publickey
# gerrit
Host 192.168.123.123 | gerrit.com
HostName 192.168.123.123
Port 12345
User gerritUsername
IdentityFile ~/.ssh/gerrit_id_rsa
PreferredAuthentications publickey
Copy the code
The fields are described as follows: Host: This field can be entered at any time and multiple values can be configured at a time. This field will be used in SSH connection commands, such as:
// Format SSH -t userName@Host // Example SSH -t [email protected] // The content after @ is the same as the Host field in the preceding configCopy the code
HostName: Indicates the actual address to be linked, which can be an IP address or an available domain name. Post: indicates the port number. User: indicates the User name used to connect. The authentication mode is used preferentially. The publickey is selected here
The test link
After the preceding tests are complete, the SSH Key is configured. You can then use the SSH -t command to test whether the configured key is available. Here I have deleted the two pairs of key files used for the example, leaving only the keys available for demonstration.
use
ssh -T [email protected]
Copy the code
Command to test connections to Github. Note: When using Git for SSH connections to Github, write [email protected], not [email protected]
Again, execution
SSH -t [email protected] SSH -t [email protected]Copy the code
Command to test the connection to Gerrit.
At this point, github and Gerrit’s two separate sets of public keys are configured.