Mac端配置不同的Git账户(例如github和gitlab)

一、配置秘钥和公钥

1、执行 cd ~/.ssh

2、执行下面这条命令:
ssh-keygen -t rsa -C "[email protected]"

2、然后会出现
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/yujianbo/.ssh/id_rsa):
 
3、然后填写你要设置的名字,例如github-rsa

4、一直敲回车键

5、ls就能看到github-rsa、github-rsa.pub

6、cat github-rsa.pub,复制看到的内容填写到 github的ssh里面即可


二、在.ssh目录下面创建config文件

// 创建 & 配置 config文件,管理ssh会话
open ./
vim config

// config文件主要内容:
# gitlab
Host gitlab.4399.com gitlab.com
   HostName  你的工作代码库的host域名
   User git
   IdentityFile ~/.ssh/id_rsa
# github
Host github.com
   HostName github.com
   User git
   IdentityFile ~/.ssh/github_rsa

三、测试SSH

yujianbo@FishMAN-MacBookPro .ssh % ssh -T [email protected]
Hi FishManHome! You've successfully authenticated, but GitHub does not provide shell access.

yujianbo@FishMAN-MacBookPro .ssh % ssh -T [email protected]
Welcome to GitLab, @yujianbo4399!

四、修改配置

// 全局配置
$ git config --global user.name 'gitlab账号名'   
$ git config --global user.email '公司账号邮箱' 

git config --list 

// 本地配置
$ git config --local user.name '个人github账号名' 
$ git config --local user.email '个人github账号邮箱'



本文参考:https://blog.csdn.net/cynthia101/article/details/103720884/

你可能感兴趣的:(Mac端配置不同的Git账户(例如github和gitlab))