GitlabGit使用Git

配置多个SSH-Key

2017-04-16  本文已影响453人  York_魚

为了安全性,个人的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。

上一篇 下一篇

猜你喜欢

热点阅读