Git manuals: How to use HTTPS and ssh differently

Source: Internet
Author: User

In the administration of git projects, most of the time is directly using the HTTPS URL cloning to local, of course, some people use the SSH URL to clone to the local. The main difference between the two methods is: using the HTTPS URL cloning is easier for beginners, copy the HTTPS URL and then go to git bash directly cloned to the local clone command, but each fetch and push code need to enter the account and password, This is also the problem of HTTPS mode. Using SSH URL cloning requires you to configure and add SSH key before cloning, so if you want to clone with an SSH URL, you must be the owner of the project. Otherwise you will not be able to add SSH key, and ssh by default, each fetch and push code do not need to enter the account and password, if you want to enter the account password each time to fetch and push can also be set. The previous few introduced the GIT blog is the use of HTTPS as a case, today is mainly to record how to configure the use of SSH to commit and clone code.

Step 1: Check if SSH Key has been generated on your PC
Execute the following command under Git bash

cd  ~/.sshls

These two commands are to check if a id_rsa.pub or id_dsa.pub file already exists, and if the file already exists, you can skip step 2 and go directly to step 3.

Step 2: Create an SSH Key
Execute the following command under Git bash

ssh-keygen  -t  RSA -c  " your email address " 

Code parameter meaning:
-t Specifies the key type, the default is RSA, can be omitted.
-C Sets the comment text, such as the mailbox.
-f Specifies the key file store file name.
The above command omits the-f parameter, so running the above command will allow you to enter a file name to hold the SSH key code you just generated, such as:
Generating public/private RSA key pair.
enter file in which to save the key (/C/USERS/YOU/.SSH/ID_RSA): [Press Enter]
Of course, you can also not enter a file name, using the default file name (recommended), then generates ID_ RSA and id_rsa.pub two secret key files. The
will then prompt you to enter the password two times (the password is the password you want to enter when you push the file, not the GitHub manager's password), of course, you can also do not enter the password, directly press ENTER. Then push will not need to enter a password, directly submitted to the GIT server, such as:
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Connect Down, the following hints are displayed, such as:
Your identification has been saved In/c/users/you/.ssh/id_rsa.
Your Public Key has been saved in/c/users/you/.ssh/id_rsa.pub.
The key fingerprint is:
01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your email address
When you see this display on Git bash, That means that your SSH key has been created successfully and you just need to add it to ssh key on the git server.

Step 3: Add SSH key to the GIT server
This is due to different git servers, the interface added in the area is not the same, so do not elaborate, specific reference to different Git server's own operations.
After the above three steps, you can happily use the SSH URL to submit and clone the code of the project, and do not need to enter the account password frequently, if you have been using the HTTPS method of development, currently want to switch to SSH mode for development, You only need to do the following steps:

add"Git仓库的ssh格式地址"push origin

Git manuals: How to use HTTPS and ssh differently

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.