Git配置多个SSH-Key

生成秘钥

一、 设置邮箱用于访问远程git服务器

设置全局的用户名和邮箱,全局有效

git config --global user.name "your name"
git config --global user.email "your email"

设置局部的的用户名和邮箱,仅在当前目录下生效

git config user.name "your name"
git config user.email "your email"

建议配置为全局,这样就不用每次进行校验

查看全局的用户名

git config --global user.name
git config --global user.email

局部查看

git config user.name
git config --global user.email
二、 生成密匙并关联服务器
生成密匙
ssh-keygen -t rsa -C "your.email@example.com" -b 4096  -f ~/.ssh/gid_rsa

作为与github区分需要修改key文件的文件名

在这里插入图片描述

新建一个conf文件:
用于区分gitlab与github读取配置文件的路径

# gitlab
Host 192.168.1.248
    HostName gitlab.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/gid_rsa
# github
Host github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa
  • Host 代表域名或者ip地址
  • HostName 代表需要连接的主机名称
  • PreferredAuthentications 拿pub文件校验
  • IdentityFile 私钥的路径

设置hosts文件:
增加一条映射
192.168.1.248 gitlab.com

验证

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值