Loading

Gitlab/Github 多 SSH 配置

公司升级了gitlab,导致操作 Git 时推拉代码不能用了,重新梳理下 SSH 的配置过程

本机生成密钥

设置Git的 user name 和 email:输入自己的用户名和邮箱

git config --global user.name "lb"
git config --global user.email "lb@***.com"

生成公钥

ssh-keygen -t rsa -C "lb@***.com"

查看公钥,将内容粘贴到 Gitlab 中的 SSH Key 中

cat ~/.ssh/id_rsa.pub 

然后就可以正常使用了

Enter passphrase for key

使用过程中不断出现这个提示,且需要不断输入密码,只需要把专用密钥添加到 ssh-agent 的高速缓存中

ssh-add -K ~/.ssh/id_rsa

在 config 中配置域名和ip

vim ~/.ssh/config

按照自己的信息输入一下格式

# gitlab

Host git.***.cn

HostName *.*.*.*

PreferredAuthentications publickey

IdentityFile ~/.ssh/id_rsa

配置 Gitlib / Github 多密钥

原理都是一样的,把之前配置好的 id_rsa、id_rsa.pub 文件重命名,比如:id_rsa_gitlab、id_rsa_gitlab.pub

然后重复以上步骤,这个时候生成的密钥就可以当作 Github 的 SSH

在 .ssh/config 中新增 Github 的 host 和 hostname 即可

posted @ 2022-08-29 10:36  BigBender  阅读(338)  评论(0编辑  收藏  举报