I found that every time I changed my computer, I had to search for how to configure multiple SSH-keys. Although there are related articles about my favorites, I was easy to forget where MY favorites had gone, so I decided to record this series of processes, and I can read them directly next time I need them
Generate the SSH KEY
Company use: ssh-keygen -t rsa -b 4096 -c “[email protected]” -f ~/. SSH /gitlab_rsa
Personal use: ssh-keygen -t rsa -b 4096 -c “[email protected]” -f ~/. SSH /github_rsa
- t specify the generated key type, a total of dsa | ecdsa | ed25519 | rsa these four - b to specify the length of key generation, dsa key length is 1024, rsa key by default is 2048, generally do not need to specify -c specifies the comment, The public key is stored in the same folder. If the file name is not known, id_rsa is generated by default, and the file name is generated in the user/.ssh folder by defaultCopy the code
Place the public key in GitLab or Github
Just copy the contents of the xx_rsa.pub file and add it to the corresponding SSH keys in gitlab or Github personal Settings
Adding a Configuration File
# gitlab Host gitlab.com HostName gitlab.com User my-gitlab-name PreferredAuthentications publickey IdentityFile ~/.ssh/gitlab_rsa # github Host github.com HostName github.com User my-github-name PreferredAuthentications publickey SSH /github_rsa # Host: this is a schema that you want to identify. Host name to log in to # User: login name # IdentityFile: specifies the IdentityFile path corresponding to the User aboveCopy the code
Test the connection
Ssh-t [email protected] or ssh-t [email protected]
If the following error occurs while trying to connect to GitHub
kex_exchange_identification: read: Connection reset by peer
We need to see if this is happening on the company network. If so, it’s probably because GitHub is blocked on the company network.
At the end of the day, just commit the code as normal