公司使用GitLab,平时还用GitHub,Git多账号SSH,如何配置?

前言

作为程序员GitHub肯定是必不可少要上的,但是现在公司一般都有自己的私有Git仓库地址,比如公司自己搭建的GitLab仓库。那么,问题来了。Git多账号SSH,如何配置呢?

如何配置?

配置一个账户

  • 打开终端
  • 执行命令ssh-keygen -t rsa -b 4096 -C "[email protected]"
  • 依照提示,输入文件路径以及名字
  • 添加到SSH-AGENT中,ssh-add -K ~/.ssh/id_rsa
  • 复制~/.ssh/id_rsa.pub的内容,添加到GitHub或者GitLab账户上

配置多个账户

生成多个SSH key步骤跟上面一样,生成文件的时候起不同的名字即可。

编辑 ~/.ssh/config文件 没有就创建。

# github
Host github.com
Port 22
HostName github.com
PreferredAuthentications publickey
AddKeysToAgent yes
IdentityFile ~/.ssh/github_id_rsa
UseKeychain yes
User iisheng

# gitlab
Host gitlab.iisheng.cn
Port 22
HostName gitlab.iisheng.cn
PreferredAuthentications publickey
AddKeysToAgent yes
IdentityFile ~/.ssh/gitlab_id_rsa
UseKeychain yes
User iisheng

完事,愉快的去玩耍吧。

欢迎关注个人微信公众号【如逆水行舟】,用心输出基础、算法、源码系列文章。

猜你喜欢

转载自blog.csdn.net/butonce/article/details/106835772
今日推荐