Using SSH key to establish communication with the GIT server

Source: Internet
Author: User

1. In the past, everyone seems to be using HTTPS to synchronize the code with GIT, but after the new company, the director said to be equipped with SSH key, so probably understand

An SSH key allows establish a secure connection between your computer and GitLab (or GitHub).

SSH key is to allow two machines to use SSH between the user name and password is not required. The implementation of the principle is because git can save a private key on the computer, and then fill out your own public key on the GIT server, so that when you use the git command to update code or commit code, the GIT server automatically through the public and private keys to verify the identity of the client, The purpose of entering the user name and password is waived. Here are the steps to generate a public private key

2. Steps

    • Check if SSH keys exists
    • Generate a new SSH key
    • Add SSH key to GitHub
1. Check if SSH keys exists

Enter the following command, if there is a file id_rsa.pub or id_dsa.pub , go directly to step 3 to add SSH key to GitHub, otherwise enter the second step to generate SSH key

Ls-al ~/. SSH # Lists the files in your. SSH directory, if they exist

Or, see if you have this file locally with the following command.

Cat ~/. ssh/id_rsa.pub

If you can see a long list of characters starting with Ssh-rsa or SSH-DSA, then it proves that you have SSH in your local area.

2. Generate a new SSH key

First step: Generate Public/private RSA key pair
On the command line, enterssh-keygen -t rsa -C "[email protected]"

The default is to generate and two files under the corresponding path (/your_home_path) id_rsa id_rsa.pub , as shown in the following code

Ssh-keygen-T Rsa-c"[email protected]"# Creates a newSSHkey using the provided emailgenerating public/private RSA key pair. #This command would prompt you fora location and filename to store the keypair and fora password. When prompted forthe location and filename, youcan press ENTER to use the default. Enterfile inch whichTo save the key (/your_home_path/.SSH/ID_RSA):

Step Two: Enter passphrase (this step can be skipped)

When you set up passphrase, when you do version control, you will be asked to enter passphrase each time you communicate with GitHub to avoid some "mistakes"

 for no passphrase): [Type a passphrase]enter same passphrase again: [Type passphrase again]

Sample result:

 in/your_home_path/. ssh/ in/your_home_path/. ssh/id_rsa.pub.The key fingerprint is:#: 0f:f4:3b:ca::d6: A1 : 7d:f0:9d:f0:a2:db [email protected]

Step three: Add the newly generated key to the ssh-agent:

The above command can generate SSH key and save it in your local

Please copy the complete key starting with and ssh- ending with your username and host.

To copy your public key to the Clipboard, use code below. Depending on your OS "ll need to use a different command:

Windows:

clip < ~/.ssh/id_rsa.pub

Mac:

pbcopy < ~/.ssh/id_rsa.pub

Gnu/linux (Requires Xclip):

xclip -sel clip < ~/.ssh/id_rsa.pub

3. Add SSH key to GitHub

Open the file with your favorite text editor, where id_rsa.pub the information is SSH key, which is copied to the GitHub Add SSH key page

Different operating systems, there are some commands to directly copy SSH key from the file to the Clipboard, as follows:

Mac

pbcopy < ~/.ssh/id_rsa.pub# Copies the contents of the id_rsa.pub file to your clipboard

Windows

clip < ~/.ssh/id_rsa.pub# Copies the contents of the id_rsa.pub file to your clipboard

Linux

sudo apt-get install xclip# Downloads and installs xclip. If you don‘t have `apt-get`, you might need to use another installer (like `yum`)xclip -sel clip < ~/.ssh/id_rsa.pub# Copies the contents of the id_rsa.pub file to your clipboard

Add the public key of SSH key to the SSH tag on GitHub or gitlib.

Using SSH key to establish communication with the GIT server

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.