1.生成帐号 A 的 SSH Key,并在帐号 A 的 Gitee 设置页面添加 SSH 公钥:
ssh-keygen -t ed25519 -C "Gitee User A" -f ~/.ssh/gitee_user_a_ed25519
2.生成帐号 B 的 SSH-Key,并在帐号 B 的 Gitee 设置页面添加 SSH 公钥:
ssh-keygen -t ed25519 -C "Gitee User B" -f ~/.ssh/gitee_user_b_ed25519
3.创建或者修改文件 ~/.ssh/config,添加如下内容:
Host gt_a
User git
Hostname gitee.com
Port 22
IdentityFile ~/.ssh/gitee_user_a_ed25519
Host gt_b
User git
Hostname gitee.com
Port 22
IdentityFile ~/.ssh/gitee_user_b_ed25519
4.用 ssh 命令分别测试两个 SSH Key:
$ ssh -T gt_a
Hi Gitee User A! You've successfully authenticated, but GITEE.COM does not provide shell access.
$ ssh -T gt_b
Hi Gitee User B! You've successfully authenticated, but GITEE.COM does not provide shell access.
如果出现错误或者权限问题 chmod 700 ~/.ssh/, chmod 600 ~/.ssh/
5. 克隆项目
将 git@gitee.com 替换为 SSH 配置文件中对应的 Host,如原仓库 SSH 链接为:
git clone gt_a:owner/repo.git
git clone gt_b:owner/repo.git
网友评论