We have a gitlab in our daily work and some of our own projects on GitHub. This leads us to configure different ssh-key to correspond to different environments. Let's take a look at the specific operation:
1, generate a company Ssh-key
$ ssh-keygen-t rsa-c "[email protected]"-F ~/.ssh/id-rsa
The ~/.ssh/directory generates the ID-RSA and id-rsa.pub private and public keys. We pasted the contents of the id-rsa.pub into the Ssh-key configuration of the company's Gitlab server.
2, generate a Ssh-key for GitHub
$ ssh-keygen-t rsa-c "[email protected]"-F ~/.ssh/github-rsa
The ~/.ssh/directory generates the GITHUB-RSA and github-rsa.pub private and public keys. We pasted the contents of the github-rsa.pub into the Ssh-key configuration of the GitHub server.
3, add private key
$ ssh-add ~/.ssh/id_rsa $ ssh-add ~/.ssh/id_rsa_github
If you are prompted "Could not open a connection to your authentication agent" When you execute Ssh-add, you can now execute the command:
$ 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
4. Modify the configuration file
Create a new config file under the ~/.ssh directory
Touch Config
Add Content:
# gitlabhost gitlab.com HostName gitlab.com preferredauthentications publickey identityfile ~/.ssh/id_ rsa# githubhost github.com HostName github.com preferredauthentications publickey identityfile ~/.ssh/ Id_rsa_github
5, directory structure
6, Test
$ ssh-t [email protected]
Output
Hi stefzhlg! You've successfully authenticated, but GitHub does not provide shell access. It means that the success is connected to GitHub. You can also try linking the company's Gitlab.
git configures multiple Ssh-key