Git different warehouses use different keys

Time:2022-5-6

Generate key

Git different warehouses use different keys

ssh-keygen -t rsa
#I generate the key in ~ / In SSH / GitHub directory, the file name is leonard repo, and the file is as follows:
# ~/.ssh/github/leonard-repo
# ~/.ssh/github/leonard-repo.pub
#View public key: cat ~ / ssh/github/leonard-repo. pub

Add key in GitHub

Web page GitHub Com – > a warehouse [assuming Leonard repo] – [setting – > deploy keys
Git different warehouses use different keys
Create a new key and put Leonard repo Pub copies the contents of the public key to it

Local settings

SSH settings

Edit ~ / SSH / config, add the following

#Leonard repo is now GitHub Alias of COM
#Setting an alias is to prevent interference with other warehouses
#The name should be chosen casually, but it should be consistent with the setting of GIT local warehouse later

# github.com/leonard/leonard-repo
Host leonard-repo
Hostname github.com
identityFile ~/.ssh/github/leonard-repo
User git

Git local warehouse settings

editProject / git/config

hold

[remote "origin"]
    url = [email protected]:leonard/leonard-repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*

GitHub in COM is changed to Leonard repo, which is as follows

[remote "origin"]
    url = [email protected]:leonard/leonard-repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*

END