gitlab和github同时使用

1.创建github秘钥

$ ssh-keygen -t rsa -C "youremail@gmail.com"    

注意,这时不能一路回车,否则邮箱将覆盖默认gitlab的ssh key,给这个文件起一个名字, 比如叫 id_rsa_github, 所以相应的也会生成一个 id_rsa_github.pub 文件。

image.png

此时查看.ssh下的目录文件(C:\Users\pengfei.yin.ssh),发现多了id_rsa_github和id_rsa_github.pub两个文件。

2.添加配置识别不同仓库提交到不同位置

.ssh 文件夹下里面创建一个 config 文件

touch config

文件内容会自动生成,不用修改,如下

# gitlab
Host gitlab.com
    HostName gitlab.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa
# github
Host github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_github    

同理,要是再增加码云地址,创建私钥步骤同上,config再增加类似的代码即可。

 # gitee
 Host gitee.com
     HostName gitee.com
     PreferredAuthentications publickey
     IdentityFile ~/.ssh/id_rsa_gitee

3.克隆文件

当第一次进行git clone 仓库地址时,会提示
当你输入以上代码时,会有一段警告代码。如:

The authenticity of host 'github.com (207.97.227.239)' can't be established.
# RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
# Are you sure you want to continue connecting (yes/no)?

这是正常的,你输入 yes 回车既可克隆项目。后面再克隆其他仓库不会出现该验证提示。

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

推荐阅读更多精彩内容