1、进入.ssh文件
cd ~
cd .ssh
2、生成 GitHub 和 gitlab 对应的公/私密钥
ssh-keygen -t rsa -C 'gitlab邮箱' -f ~/.ssh/id_rsa_gitlab
ssh-keygen -t rsa -C '注册github账户的邮箱'
//两次回车直接生成个人邮箱相关密钥
3、可以通过 ls 查看刚才生成的文件
//此时,可以看到以下文件
id_rsa id_rsa.pub id_rsa_gitlab id_rsa_gitlab.pub known_hosts
4、创建&配置config文件,管理ssh会话
touch config
vim config
按i键进入编辑状态,输入以下代码
Host github.com
HostName github.com
User xxx@qq.com //user后边为github的邮箱
IdentityFile ~/.ssh/id_rsa
Host gitlab.xxx.cn //host后边为公司gitlab域名
HostName gitlab.xxx.cn //同上为公司gitlab域名
User xxx@163.com //user可以根据自己配置设置,可以写公司邮箱
IdentityFile ~/.ssh/id_rsa_gitlab
5、测试SSH连接
ssh -T git@github.com //这个-T 后边的是你上边 Host 后边的配置
ssh -t git@gitlab.xxx.cn
6、全局配置,要不 gitlab 提交提示
$ git config --global user.name '个人gitLab账号名'
$ git config --global user.email '个人gitLab账号邮箱'
mac 配置 gitLab 和 GitHub
最新推荐文章于 2025-04-11 13:07:45 发布