同时配置多个 git 账号

多个账号配置 ssh

  1. 生成公私钥

    1
    2
    ssh-keygen -t rsa -C "邮箱地址" -f ~/.ssh/work_id_rsa
    ssh-keygen -t rsa -C "邮箱地址" -f ~/.ssh/github_id_rsa
  2. 公钥(*.pub)copy到平台上

    1
    2
    cat ~/.ssh/work_id_rsa.pub
    cat ~/.ssh/github_id_rsa.pub
  3. 修改config文件

    1
    2
    3
    4
    5
    6
    7
    8
    Host work.domain.com
    HostName work.domain.com
    User git
    IdentityFile ~/.ssh/work_id_rsa

    Host github.com
    HostName github.com
    IdentityFile ~/.ssh/github_id_rsa

测试配置结果

1
2
ssh -T git@github.com
Hi LeungGeorge! You've successfully authenticated, but GitHub does not provide shell access.

image-20221210105213725

0%