Because the company team uses GITLAB to host the code, while the individual on Github also has some code warehouse, the company mailbox and personal mailbox is different, the resulting SSH key is also different, which caused the conflict, the article provides solutions to such problems: how to use the same on a machine Github and Gitlab services?
1. Generate SSH Key for Github/gitlab
$ ssh-keygen-t rsa-f ~/.ssh/id_rsa_github-c "[email protected]" $ ssh-keygen-t rsa-f ~/.ssh/id_rsa_gitlab-c "[Email p Rotected] "
Check if key is generated
$ ls ~/.ssh
2. Add private key
$ ssh-add ~/.ssh/id_rsa_github$ Ssh-add ~/.ssh/id_rsa_gitlab
If you are prompted "Could not open a connection to your authentication agent" When you execute Ssh-add, you can execute the command first:
$ ssh-agent Bash
Then run the Ssh-add command again.
# The list of private keys can be ssh-add-l by a $ ssh-add-l# can be ssh-add-d to clear the list of private keys $ ssh-add-d
3. Modify the configuration file
$ VI ~/.ssh/config
# githubhost github.com HostName github.com preferredauthentications publickey identityfile ~/.ssh/id_ rsa_github# gitlabhost gitlab.example.com HostName gitlab.example.com preferredauthentications publickey Identityfile ~/.ssh/id_rsa_gitlab
4. Upload public key to Github/gitlab
In GitHub, for example, the process is as follows:
Login to GitHub, click on the icon at the top right and click "Settings"
Select SSH and GPG keys, click on "New ssh key", fill in the name of SSH key in the interface that appears, fill in a name you like, and then paste the contents of the ~/.ssh/id_isa_github.pub file to key
column, click on the "Add SSH Key" button to do it.
Add a process github will prompt you to enter your GitHub password once and add it after confirmation.
Taking Gitlab as an example, the process is as follows:
Click "Profile Settings"
Click "SSH keys" to add SSH key
5. Testing
# test github$ ssh-t [email protected]# test gitlab$ ssh-t [email protected]
CentOS7 on Github/gitlab multiple account management ssh Key