多个.ssh密钥对时
添加密钥wgc
$ ssh-keygen -t rsa -C "admin1@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
/c/Users/Administrator/.ssh/id_rsa_wgc
添加密钥mlj
$ ssh-keygen -t rsa -C "admin2@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
/c/Users/Administrator/.ssh/id_rsa_mlj
密钥添加到SSH agent中
因为默认只读取id_rsa,为了让SSH识别新的私钥,需将其添加到SSH agent中:
$ ssh-agent bash
$ ssh-add ~/.ssh/id_rsa_wgc
$ ssh-add ~/.ssh/id_rsa_mlj
修改(新建)config文件
在~/.ssh目录下找到config文件
Host wgc
HostName gitee.com
User git
IdentityFile C:\Users\Administrator\.ssh\id_rsa_wgc
Host mlj
HostName gitee.com
User git
IdentityFile C:\Users\Administrator\.ssh\id_rsa_mlj
添加公钥到平台:
测试
$ ssh -T git@gitee.com
$ ssh -T wgc
$ ssh -T mlj
若返回:
Welcome to Gitee.com, yourname!
表示成功!
TortoiseGit配置:
设置->网络->SSH客户端 C:\Program Files\Git\usr\bin\ssh.exe
TortoiseGit添加URL时有点不一样
git@gitee.com就用wgc和mlj代替,因为要对应不同的key!!!