1. Check if your computer already has an SSH Key?
Run the following command to view:
$ cd ~/.ssh
$ ls
If id_rsa.pub
the or id_dsa.pub
file exists, it means that your computer already has it SSH Key
and can be used directly. If not, it needs to be created.
2. Create SSH Key
- Configure the global
name
sumemail
, here isgithub
yourname
sumemail
.
git config --global user.name "XXX"
git config --global user.email "[email protected]"
As shown below:
- generate key
ssh-keygen -t rsa -C "[email protected]"
As shown below:
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 ls
to view it, as shown in the following figure:
- view private key
cat ~/.ssh/id_rsa
- view public key
cat ~/.ssh/id_rsa.pub
As shown below:
Copy the generated public key SSH Key
and configure it in the warehouse that needs to be added. As shown below:
Paste in the input box as shown in the figure below key
to complete the configuration
After the addition is successful, as shown in the figure below:
3. Verify identity
SSH key
After 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:
4. Code hosting
SSH key
The 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:
Associate the local project with git
the device, and then push it. You need to enter the password of the computer to push it successfully, as shown in the figure below: