创建多个ssh key
1.创建新的ssh key
$ ssh-keygen -t rsa -C "your.email@example.com" -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/home/xxx/.ssh/id_rsa):
设置文件名,注意这里要写绝对路径,如/home/xxx/.ssh/new_rsa
2. 将密钥添加到SSH agent中
$ ssh-add ~/.ssh/id_new_rsa
若显示权限问题,执行sudo chmod 600 ~/.ssh/new_rsa
ssh-add -l
可以查看添加过的密钥
ssh-add -D
可以删除密钥
3.查看密钥,并将密钥添加到git上
$ cat ~/.ssh/id_new_rsa.pub
用同样的方式可添加多个
配置基于Host的差异配置
$ vim ~/.ssh/config
Host gitlab.xxx.com
HostName gitlab.xxx.com
User user
IdentityFile ~/.ssh/id_new_rsa # 根据自己的private key目录修改
Host github.com
HostName github.com
User user
IdentityFile ~/.ssh/id_rsa_github # 根据自己的private key目录修改
ProxyCommand connect -S 127.0.0.1:7070 %h %p # socket proxy