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 ~/.ssh ls
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-C"你的email地址"
code parameter meaning:
- t Specifies the key type, which is RSA by default and can be omitted.
-C Set comment text, such as mailbox.
-f Specifies that the key file stores the 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 the file name, using the default file name (recommended), then the Id_rsa and id_rsa.pub two key files will be generated.
You will then be prompted 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:
Next, you will see the following hints, 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, it means that your SSH key has been created and you just need to add it to the 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
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 ~/.ssh ls
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-C"你的email地址"
code parameter meaning:
- t Specifies the key type, which is RSA by default and can be omitted.
-C Set comment text, such as mailbox.
-f Specifies that the key file stores the 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 the file name, using the default file name (recommended), then the Id_rsa and id_rsa.pub two key files will be generated.
You will then be prompted 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:
Next, you will see the following hints, 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, it means that your SSH key has been created and you just need to add it to the 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