How to manage Git code by creating SSH key

1. Check if your computer already has an SSH Key?

Run the following command to view:

$ cd ~/.ssh
$ ls

insert image description here

If id_rsa.pubthe or id_dsa.pub file exists, it means that your computer already has it SSH Keyand can be used directly. If not, it needs to be created.

2. Create SSH Key

  1. Configure the global namesum email, here is githubyour namesum email.
git config --global user.name "XXX"
git config --global user.email "[email protected]"

As shown below:

Configure global name and email

  1. generate key
ssh-keygen -t rsa -C "[email protected]"

As shown below:

generate key

Executing the command will allow you to enter the system password. If the password verification is successful key, it will be generated. You can enter the command lsto view it, as shown in the following figure:

newly produced key

  1. view private key
cat ~/.ssh/id_rsa

view private key

  1. view public key
cat ~/.ssh/id_rsa.pub

As shown below:

view public key

Copy the generated public key SSH Keyand configure it in the warehouse that needs to be added. As shown below:

insert image description here

Paste in the input box as shown in the figure below keyto complete the configuration

insert image description here

After the addition is successful, as shown in the figure below:
insert image description here

3. Verify identity

insert image description here

SSH keyAfter the configuration is successful, you need to enter the following command in the terminal to verify, you can refer to the official instructions of github

ssh -T git@github.com

If the verification is successful, there will be a success prompt, as shown in the following figure:

Verification successful

4. Code hosting

SSH keyThe configuration is successful, then the next step is definitely the need to remotely host the local code. First of all, we first associate the local project.

git remote add origin git@github.com:xxxx/项目名称.git

code push

 git push -u origin master

As shown below:

insert image description here

Associate the local project with gitthe device, and then push it. You need to enter the password of the computer to push it successfully, as shown in the figure below:

insert image description here

Guess you like

Origin blog.csdn.net/zjpjay/article/details/128458386