Git 多公钥配置

1 min

解决一个公钥无法共用问题

  1. 生成第一个密钥

    ssh-keygen -t rsa -C "[email protected]"
  2. 生成第二个公钥

    two_git 是第二个公钥的名称

    ssh-keygen -t rsa -C  "[email protected]" -f two_git
  3. .ssh 目录新建 config 文件

    windows下的 .ssh 目录 在 C:\Users\username

  4. config 文件配置

    # 账号一Host gitee.com
    HostName gitee.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa
    HostkeyAlgorithms +ssh-rsa
    PubkeyAcceptedAlgorithms +ssh-rsa
    # 账号二# giteeHost two.gitee.com
    HostName gitee.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/two_git
    HostkeyAlgorithms +ssh-rsa
    PubkeyAcceptedAlgorithms +ssh-rsa
  5. 使用 ssh 的方式克隆仓库

    1. 使用账号一克隆代码

      git clone [email protected]:xxxxxxx
    2. 使用账号二克隆代码

      git clone [email protected]:xxxxxxx

完。