工作以后在公司都是使用公司自己搭建的gitlab仓库,但是因为保密问题只能通过内网访问,所以平时自己的项目还是会放在GitHub和GItee,但是之前写过一篇GItHub如何配置SSH Key,但是也只是配置GIthub,尝试一下同时配置。
安装Git
我的系统是Ubuntu,是apt安装
sudo apt install git
生成新的ssh keys
1)GitHub
指定文件路径,方便后面操作:~/.ssh/id_rsa.gitlab
ssh-keygen -t rsa -f ~/.ssh/id_rsa.github -C "zcy_nemo@aliyun.com"
2)Gitee
ssh-keygen -t rsa -f ~/.ssh/id_rsa.gitee -C "zcy_nemo@aliyun.com"
生成的文件:
添加识别 SSH keys 新的私钥
因为默认只读取 id_rsa,为了让 SSH 识别我们分别设置的密钥,所以将新的私钥加入到 SSH agent 中:
muyi@muyi:~$ ssh-agent bash
muyi@muyi:~$ ssh-add ~/.ssh/id_rsa.github
Identity added: /home/muyi/.ssh/id_rsa.github (zcy_nemo@aliyun.com)
muyi@muyi:~$ ssh-add ~/.ssh/id_rsa.gitee
Identity added: /home/muyi/.ssh/id_rsa.gitee (zcy_nemo@aliyun.com)
配置 config 文件
#Default gitHub user Self
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa.github
#gitee
Host gitee.com
Port 22
HostName gitee.com
User git
IdentityFile ~/.ssh/id_rsa.gitee
在 github 和 gitee 添加 ssh
github
gitee
测试
muyi@muyi:~$ ssh -T git@github.com
Hi pomole! You've successfully authenticated, but GitHub does not provide shell access.
muyi@muyi:~$ ssh -T git@gitee.com
The authenticity of host 'gitee.com (212.64.62.183)' can't be established.
ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
Are you sure you want to continue connecting (yes/no/[fingerprint])? y
Please type 'yes', 'no' or the fingerprint: yes
Warning: Permanently added 'gitee.com,212.64.62.183' (ECDSA) to the list of known hosts.
Hi Nemo丶! You've successfully authenticated, but GITEE.COM does not provide shell access.
完成!