git configures multiple Ssh-key

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.