惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
P
Palo Alto Networks Blog
月光博客
月光博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
InfoQ
aimingoo的专栏
aimingoo的专栏
腾讯CDC
T
Threatpost
D
DataBreaches.Net
Vercel News
Vercel News
F
Fortinet All Blogs
Engineering at Meta
Engineering at Meta
C
Cybersecurity and Infrastructure Security Agency CISA
Forbes - Security
Forbes - Security
U
Unit 42
C
Check Point Blog
Blog — PlanetScale
Blog — PlanetScale
O
OpenAI News
量子位
TaoSecurity Blog
TaoSecurity Blog
Microsoft Azure Blog
Microsoft Azure Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
V
Visual Studio Blog
Recorded Future
Recorded Future
云风的 BLOG
云风的 BLOG
Security Archives - TechRepublic
Security Archives - TechRepublic
The Last Watchdog
The Last Watchdog
S
Security Affairs
Attack and Defense Labs
Attack and Defense Labs
罗磊的独立博客
Stack Overflow Blog
Stack Overflow Blog
Microsoft Security Blog
Microsoft Security Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
小众软件
小众软件
S
SegmentFault 最新的问题
www.infosecurity-magazine.com
www.infosecurity-magazine.com
W
WeLiveSecurity
AI
AI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 聂微东
I
Intezer
Know Your Adversary
Know Your Adversary
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
博客园_首页
NISL@THU
NISL@THU
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO

博客园 - wjwdive

如何使用git submodule拆分大的git项目 记录一次flutter boost5.0.2示例调试的过程 【算法】可获得的最大点数问题 使用1panel一键建站 关于混合加密(AES+RSA) C++设计模式汇总 设计模式C++005__桥模式 设计模式C++007__抽象工厂方法模式 设计模式C++004__装饰器模式 设计模式C++003__观察者模式 设计模式C++002__策略模式 设计模式C++001__模板方法 使用bundler自动化构建Xcode项目时遇到的问题。 AI图片生成网站 suno AI编曲创作利器 iOS组件化开发之私有库 iOS、Android获取apk公钥MD5信息 阿里图标库批量下载iOS适配的图标 C语言实现回调函数标准方式 swift 自定义tabbar为基本结构的项目 swift 可选类型
MAC多github账号配置步骤
wjwdive · 2026-04-27 · via 博客园 - wjwdive

文章最早发布于:https://blog.jarvissky.com/console/posts/editor?name=b2a947b1-c3d4-4718-8e17-deebfe0c23db

1、准备多个github账号

自行注册,可以用国内qq或者163账号注册.也可以其他国外邮箱注册。

2、配置两个github账号的步骤

2.1 本地生成密钥对

打开终端

生成密钥对, ssh-keygen -t rsa -C "your-email-1"

上面的命令RSA密钥长度github不推荐,继续使用,推荐加上 -b 4096

ssh-keygen -t rsa -b 4096 -C "your-email-1"

按提示输入,一路点击确定就好。生成好id_rsa和id_rsa.pub分别是私钥和公钥,位置在~/.ssh目录下:

重复以上步骤,再生成账号2的公私钥对

ssh-keygen -t rsa -b 4096 -C "your-email-2"

需要改名字,使得密钥对的名字 和账号1不同例如

your-email-1对应的密钥对:id_rsa_name, id_rsa_name.pub

your-email-2对应的密钥对:id_rsa_name2, id_rsa_name2.pub

也可以使用新的密钥对生成方法(推荐,默认名称样式不同,注意修改过config配置文件):

ssh-keygen -t ed25519 -C "你的邮箱"

更小,加解密更快。

生成第二个密钥对的时候记得改一下默认的名字,防止覆盖。

2.2 配置config文件

让MAC区分不同的密钥对对应不同的git账号

说明,如果使用了代理,有时不同IDE不能提交代码,尤其是在不同的AI 编辑器中,例如Codex, TRAE中,需要指明你的代理端口。

# GitHub

Host github.com

  HostName github.com

  User git

  IdentityFile ~/.ssh/id_rsa_name

  ProxyCommand nc -x 127.0.0.1:7897 %h %p


# another github account

Host github_name2.com

  HostName github.com

  User git

  IdentityFile ~/.ssh/id_rsa_name2

  ProxyCommand nc -x 127.0.0.1:7897 %h %p

重点:

1、两个账号的Host 字段一定要不一样,例如:Host github_name2.com和Host github.com,后续依此区分使用哪个git账号。
2、HostName,User 字段必须固定,绝对不能更改。
3、 IdentityFile必须是和你将要使用的公私钥对一致。
4、‘ ProxyCommand nc -x 127.0.0.1:7897 %h %p 指明走代理加速,不走代理的话,不要写这一行:
nc:netcat 工具,负责建立网络连接
-x:使用代理(SOCKS5 代理)
127.0.0.1:7897:你的本地代理地址(大力工具的默认端口)
%h:自动替换成目标主机(github.com)
%p:自动替换成目标端口(22)

2.3 登录github账号1

点击自己的头像--> setting --> SSH and GPG keys,
我们只需要配置SSH,把id_rsa_name.pub中的公钥串复制到 github中。另一个账号也做同样操作,添加id_rsa_name2.pub。

3、使用

如果你设置 账号1位全局适配,那么你想要使用账号2,或者其他账号,需要在你的项目目录取消账号1的全局生效。
你可以设置一个默认的全局账号,那么在任何项目中默认使用这个账号,例如账号1, name1

git config --global user.name "你的全局名字"
git config --global user.email "全局邮箱"

git config --list
命令查看git全局配置情况,确认你想使用的默认账号是账号1:

 % git config --list
credential.helper=osxkeychain
init.defaultbranch=main
user.name=xxx
user.email=xxx@163.com
user.signingkey=xxx
commit.gpgsign=false
safe.directory=*

如果要 删除全局设置

git config --global --unset user.name
git config --global --unset user.email

由于局部项目的git权重较高,你只需要在你的项目目录设置好本地生效的git账号即可。

git config user.name "第二个账号名字"
git config user.email "第二个账号邮箱"

查看本地项目的git生效账户:

git config user.name
git config user.email

有了以上知识,就可以安全的配置本地项目账号了

例如你默认的git账号1,然后你想在新的目录使用git账号2,操作步骤:

1、必须切换到项目的目标路径
2、配置git账号2
3、和git账号2的远程仓库关联

# 1
cd /your/project/path

# 2
git config user.name "例如工作账号"
git config user.email "例如work@xxx.com"

# 3 注意这里的Host是github_name2.com
git remote set-url origin git@github_name2.com:用户名/仓库.git

其他使用默认账户1的命令host要使用对应的Host。github.co.例如

git remote set-url origin git@github.com:用户名/仓库.git

剩下的操作就是正常的git操作了。

思考:
你知道如何在本地继续添加gitlab,gitee以及你的服务器git服务相关的账号配置以及如何灵活切换和使用吗?