Use ~ / .ssh / config file

Host github-A
    HostName github.com
    User git
    IdentityFile /Users/xxx/.ssh/id_rsa_A
    IdentitiesOnly yes
Host github-B
    HostName github.com
    User git
    IdentityFile /Users/xxx/.ssh/id_rsa_B
    IdentitiesOnly yes

 

config files are saved in different host ssh keys used.

scenes to be used:

problem

Do you have multiple accounts in github, when push code needs to use a different ssh-key, but git remote -v see the default is [email protected] : xxxRepo / xxx.git (git user name, github.com Host is the name). As a result, the use of a configuration is the same, with a private key.

Solution:

As above, two different configurations Host. Then under the repo, Git Remote SET-URL Origin Git @ GitHub-A: repoA / xxx.git can distinguish the

config configuration Meaning

  • Host
    Host is used to specify the name of the key, and here you must use local repo's hostname github-A.
    HostMust be followed by the repo hostnameagreement remain, that will use their own time to git repo is hostnameto find ssh configuration file which is not a corresponding Host, found on the use of this configuration, the domain name will be used to access specificHostName
  • Hostname
    Specified here Hostcorresponds to a specific domain name
  • User git
    Description of the configuration of the user is obtained git
  • IdentityFile /Users/xxx/.ssh/id_rsa.github
    This is the most critical line, which specifies the use of ssh key file, here's some key document refers to the private key file.
  • IdentitiesOnly yes
    Configured to yesthe specific meaning can refer to the discussion . This configuration file can be ignored.



Author: drying rack balcony
link: https: //www.jianshu.com/p/45201d18cc7c
Source: Jane books

Guess you like

Origin www.cnblogs.com/cangqinglang/p/11727867.html