1. Use git to generate ssh key
1. Install git client on Mac
Open the terminal and execute the command:
$ brew install git
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]” (你的邮箱)
id_rsa
Two files , private key and public key, will be generated in the .ssh directory id_rsa.pub
, as follows:
6. View the public key, copy the entire public key, and configure it to the backend such as GitCode
Copy and paste the entire ssh public key and save it.
2. Configure local SSH to sourceTree
1. Add sshkey to sourceTree
ssh-add ~/.ssh/id_rsa
2. Add sshkey to the keychain
ssh-add -K ~/.ssh/id_rsa
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]
4. Use sourcetree clone warehouse
[email protected]:xxx/xxx.git