Use git client to generate ssh key under mac and configure it to souretree for use


1. Use git to generate ssh key


1. Install git client on Mac


Open the terminal and execute the command:

$ brew install git

Insert image description here


2. Execute the command


$ git config --global user.name "xxx"                        你自己的名字
$ git config --global user.email "[email protected]"       你自己的邮箱


3. Check whether the key already exists


cd ~/.ssh

4. If you can enter it, it means it already exists. Delete the folder and create it again.


rm -rf ~/.ssh
mkdir ~/.ssh

5. Generate an SSH key, execute the following command, and press the Enter key three times in a row.


ssh-keygen -t rsa -C “[email protected]”   (你的邮箱)


Insert image description here


id_rsaTwo files , private key and public key, will be generated in the .ssh directory id_rsa.pub, as follows:

Insert image description here


6. View the public key, copy the entire public key, and configure it to the backend such as GitCode


Insert image description here

Insert image description here

Insert image description here

Copy and paste the entire ssh public key and save it.


Insert image description here


2. Configure local SSH to sourceTree


1. Add sshkey to sourceTree

ssh-add ~/.ssh/id_rsa

Insert image description here


2. Add sshkey to the keychain

ssh-add -K ~/.ssh/id_rsa

Insert image description here


3. Go to the .ssh directory and command to create the config file


cd ~/.ssh
touch config

4. Open the config file

open config

Enter the following and save

Host *
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa


3. Execute the ssh command to connect to the git server and trust the public key.

ssh  [email protected]

Insert image description here


4. Use sourcetree clone warehouse

[email protected]:xxx/xxx.git

Insert image description here

Guess you like

Origin blog.csdn.net/lizhong2008/article/details/130497521