您当前的位置:首页 > 计算机 > 软件应用 > 开发工具(IDE)

Git 配置多个 SSH-Key

时间:12-14来源:作者:点击数:
CDSY,CDSY.XYZ

一个开发者在同一台机器上拥有多个 Git 账号,是比较常见的。如 Gitee 用于工作,GitHub 用于个人,这时候往往需要配置多个 SSH-Key。

解决方法

生成 SSH-Key

# 生成 GitHub 用的 SSH-Key
$ ssh-keygen -t rsa -C 'xxx@qq.com' -f ~/.ssh/github_id_rsa

# 生成 Gitee 用的 SSH-Key
$ ssh-keygen -t rsa -C 'xxx@company.com' -f ~/.ssh/gitee_id_rsa

在 ~/.ssh 目录下的 config 文件(若没有则创建),添加如下内容:

# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id_rsa
# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitee_id_rsa

其中 Host 和 HostName 填写 Git 服务器的域名,IdentityFile 指定私钥的路径。

用 SSH 命令分别测试。

$ ssh -T git@github.com
$ ssh -T git@gitee.com

如果成功的话,会返回以下内容。

$ ssh -T git@github.com
Hi toFrankie! You've successfully authenticated, but GitHub does not provide shell access.

$ ssh -T git@gitee.com
Hi 越前君! You've successfully authenticated, but GITEE.COM does not provide shell access.

参考 Gitee(link:https://gitee.com/help/articles/4229)

CDSY,CDSY.XYZ
方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门
本栏推荐