一文学会配置Github与Gitlab双帐户

文章目录
0.具体思路
1.生成对应不一样帐号的秘钥
2.修改 config 配置文件
3.在 github 和 gitlab 上添加我的公钥
4.测试git

关键词:Github GitLab 双帐户 设置 同时起效github


0. 具体思路

在 config 文件中设置不一样的 Host ,而后对应使用不一样的 .pub 公钥文件shell

1. 生成对应不一样帐号的秘钥

1.1 生成 github 秘钥vim

$ ssh-keygen -t rsa -f ~/.ssh/id_rsa_github -C "GithubAccount"
复制代码

1.2 生成 gitlab 秘钥bash

$ ssh-keygen -t rsa -f ~/.ssh/id_rsa_gitlab -C "GitlabAccount"
复制代码



2. 修改 config 配置文件

2.1 切换到 ~/.ssh 目录ssh

$ cd ~/.ssh
$ ls
config id_rsa_github id_rsa_github.pub id_rsa_gitlab id_rsa_gitlab.pub known_hosts
复制代码

2.2 修改配置文件ide

$ sudo vim config
# github
# host 与 hostname 须要相同
Host github.com
HostName github.com
# 你的github帐号
User GithubAccount
# github对应的rsa秘钥文件
IdentityFile ~/.ssh/id_rsa_github
 # gitlab 
# host 与 hostname 须要相同
Host gitlab.com
HostName gitlab.com
# 你的gitlab帐号
User GitlabAccount
# gitlab对应的rsa秘钥文件
IdentityFile ~/.ssh/id_rsa_gitlab
复制代码


3. 在 github 和 gitlab 上添加我的公钥

3.1 打开 Settings gitlab

在这里插入图片描述

3.2 新建 SSH Key测试

在这里插入图片描述

3.3 填写 title 和 keyui

将对应的 xx.pub 文件内容复制到 key 里面就行

好比,我要配置的是 github 帐号

我就复制 ~/.ssh/id_rsa_github.pub 的内容到下图中的 Key 中去

在这里插入图片描述


4. 测试

4.1 github 测试

$ ssh -T git@github.com
Hi GithubAccount! You've successfully authenticated, but GitHub does not provide shell access.
# 出现上边这句,表示链接成功
复制代码

4.2 gitlab 测试

$ ssh -T git@gitlab.com
Hi GitlabAccount! 
复制代码
相关文章
相关标签/搜索