Mac配置GitLab和GitHub账户
发布日期:2022-02-22 16:04:52 浏览次数:27 分类:技术文章

本文共 2467 字,大约阅读时间需要 8 分钟。

如何在一台电脑上配置GitLab账号和GitHub账号【mac】

前言

作为一个开发者,在我们的工作中,经常会想要维护一个自己的代码库和工作中用的代码库,但是配置它们又是一项比较复杂麻烦的事情,下面分享给大家一些自己配置过程中的步骤以及注意事项。

配置步骤

一、生成SSH密钥 & 配置

  1. 在Terminal终端中使用ssh-keygen -t rsa -C "公司邮箱地址"生成对应的gitlab密钥:id_rsa和id_rsa.pub
  2. 将gitlab公钥即id_rsa.pub中的内容配置到公司的gitlab上
  3. 在Terminal终端中使用ssh-keygen -t rsa -C “github地址” -f ~/.ssh/github_rsa生成对应的github密钥:github_rsa和github_rsa.pub
  4. 将github公钥即github_rsa.pub中的内容配置到自己的github上
  5. 进入密钥生成的位置,创建一个config文件,添加配置:

我们在Terminal终端对Git进行了一系列的配置:

// 进入ssh文件夹xuhao@bogon ~$ cd ~xuhao@bogon ~$ cd .sshxuhao@bogon .ssh$ ssh-keygen -t rsa -C "你的工作邮箱"// 两次回车直接生成工作邮箱相关密钥xuhao@bogon .ssh$ lsid_rsa     id_rsa.pubxuhao@bogon .ssh$ ssh-keygen -t rsa -C "你的个人邮箱" -f ~/.ssh/github_rsa// 两次回车直接生成个人邮箱相关密钥xuhao@bogon .ssh$ lsgithub_rsa     github_rsa.pub id_rsa         id_rsa.pub// 创建 & 配置 config文件,管理ssh会话xuhao@bogon .ssh$ open ./xuhao@bogon .ssh$ vim config// config文件主要内容:# gitlabHost gitlab 别名   HostName  你的工作代码库的host域名   User git   IdentityFile ~/.ssh/id_rsa# githubHost github.com   HostName github.com   User git   IdentityFile ~/.ssh/github_rsaxuhao@bogon .ssh$ lsconfig         github_rsa     github_rsa.pub id_rsa         id_rsa.pub

二、测试SSH连接

xuhao@bogon .ssh$ ssh -T git@github.comThe authenticity of host 'github.com (xxxxxxxxxxxx)' can't be established.RSA key fingerprint is SHA256: xxxxxxxxxxxxxxxxxxxxxxxxxxAre you sure you want to continue connecting (yes/no)? yesWarning: Permanently added 'github.com,xxxxxxxxxxx' (RSA) to the list of known hosts.Hi 你的github账号名! You've successfully authenticated, but GitHub does not provide shell access.xuhao@bogon .ssh$ ssh -T git@github.comHi 你的github账号名! You've successfully authenticated, but GitHub does not provide shell access.xuhao@bogon .ssh$ // 恭喜你!你的github的密钥已经配置 & 联通成功。xuhao@bogon .ssh$ ssh -T git@gitlabThe authenticity of host '你的工作代码库域名,你的工作代码库ip地址' can't be established.RSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxx.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added '你的工作代码库域名,你的工作代码库ip地址' (RSA) to the list of known hosts.Welcome to GitLab, 你的工作代码库账号名!xuhao@bogon .ssh$ ssh -T git@gitlabWelcome to GitLab, 你的工作代码库账号名!// 恭喜你!你的gitlab工作代码库的密钥已经配置 & 联通成功。

三、本地配置

// 全局配置$ git config --global user.name 'gitlab账号名'   $ git config --global user.email '公司账号邮箱' // 本地配置$ git config --local user.name '个人github账号名' $ git config --local user.email '个人github账号邮箱'

总结

至此,你的电脑上已经完成了对gitlab和github的配置联通工作。是不是,其实也没有那么麻烦呢,哈哈哈~ 亲爱的小伙伴们,如果觉得对你开发工作有帮助的话,请记得收藏点赞哦~

转载地址:https://blog.csdn.net/cynthia101/article/details/103720884 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Bootstrap模态框
下一篇:原生JavaScript+Css模拟Select下拉框,美化

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2023年09月23日 22时02分38秒