侧边栏壁纸
  • 累计撰写 47 篇文章
  • 累计收到 0 条评论

Linux 配置多个 SSH-Key

2019-1-19 / 0 评论 / 183 阅读
温馨提示:
本文最后更新于 2019-1-19,已超过半年没有更新,若内容或图片失效,请留言反馈。

为了安全性,个人的 GitHub 和公司的 GitLab 需要配置不同的 SSH-Key

1.切换到系统的 ssh 目录

cd ~/.ssh

2.为个人的 GitHub 生成 SSH-Key(若还没有)

ssh-keygen -t rsa -C "your_mail@example.com" -f github_rsa

然后,前往 GitHub 添加 SSH公钥

3.为公司的 GitLab 生成 SSH-Key(若还没有)

ssh-keygen -t rsa -C "your_mail@company.com" -f company_rsa

然后,前往 GitLab 添加 SSH公钥

4.添加配置文件(若还没有)

touch config

5.为配置文件 config 添加如下内容

# github.com
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_rsa

# gitlab.company.com
Host gitlab.company.com
HostName gitlab.company.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/company_rsa

6.测试

ssh -T git@github.com

输出 : Hi YK-Unit! You've successfully authenticated, but GitHub does not provide shell access.

以上表示成功连接到了个人的 GitHub
然后可以用同样方式测试公司的 GitLab

评论一下?

OωO
取消