git 添加多个ssh密钥

本文介绍如何在一台计算机上配置GitLab和GitHub的独立SSH密钥,包括生成密钥、修改配置文件及验证连接等步骤,实现两平台间的无缝切换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一个GitLab,一个GitHub,两个账号地址不同,需要添加两个ssh,网上找了几篇,操作成功以后做个汇总。

1、打开ssh文件夹:

cd ~/.ssh/

2、添加新的ssh密钥:

ssh-keygen -t rsa -C "youremail@app.com"

3、重命名,若一路回车名字和密码都可以不写,默认会在~/.ssh/目录下生成id_rsa。为了区分,第一个回车后可以设置文件名称:

Enter file in which to save the key (/root/.ssh/id_rsa):~/.ssh/文件名

4、复制密钥: 

cat id_rsa_mine.pub

5、密钥添加到自己的git中

6、创建config文件:

touch ~/.ssh/config

7、config文件下添加如下信息

# gitlab 
Host http:***.***.**.**/ 
HostName http://124.128.23.70/ 
PreferredAuthentications publickey 
IdentityFile ~/.ssh/id_rsa
user git

# github 
Host github.com 
HostName github.com 
PreferredAuthentications publickey 
IdentityFile ~/.ssh/id_rsa_mine
user git 

8、验证连接

ssh -T git@github.com

GitLab返回“Welcome to GitLab,##!”表示调通

GitHub返回“Hi BeginMan! You've successfully authenticated, but GitHub does not provide shell access.”表示调通

链接不成功时检测出错信息

ssh -vT git@gihub.com

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值