配置多个SSH-Key

为了安全性,个人的github和公司的gitlab需要配置不同的SSH-Key。具体如下:

  1. 切换到系统的SSH目录
cd ~/.ssh
  1. 为个人的github生成SSH-Key(若还没有)
ssh-keygen -t rsa -C "your_mail@example.com" -f github_rsa

然后,前往github添加SSH公钥。

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

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


然后,前往gitlab添加SSH公钥。

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

``` shell
touch config
  1. 为配置文件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
  1. 测试
ssh -T git@github.com

输出

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

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容