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

推荐订阅源

WordPress大学
WordPress大学
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
美团技术团队
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
月光博客
月光博客
V
Visual Studio Blog
T
Tailwind CSS Blog
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
Jina AI
Jina AI
J
Java Code Geeks
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
Recorded Future
Recorded Future
C
Check Point Blog
腾讯CDC
N
Netflix TechBlog - Medium
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
Hacker News: Ask HN
Hacker News: Ask HN
SecWiki News
SecWiki News
博客园 - Franky
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News | PayPal Newsroom
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security @ Cisco Blogs
W
WeLiveSecurity
The Last Watchdog
The Last Watchdog
Cloudbric
Cloudbric
F
Full Disclosure
The Cloudflare Blog
Y
Y Combinator Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
S
Schneier on Security
Schneier on Security
Schneier on Security
Spread Privacy
Spread Privacy
L
LINUX DO - 热门话题
AI
AI
N
News and Events Feed by Topic
T
Tor Project blog
P
Palo Alto Networks Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
G
Google Developers Blog

TimeMachine Notes

Doris 物化视图 漫谈数据库索引 工作中实践过的数据流架构 druid集群运维 doris/starrocks 碎碎念 未知的征程 doris实时数据摄入测试 之前的一些学习目标和计划 OneData探索 MR Job Counters 分析 druid 离线摄入任务优化 druid 问题记录 基于 gitbook 搭建笔记站点 Prometheus + Grafana 监控 - Kafka Mac-Homebrew-常见问题 Mac重装系统找不到磁盘主盘,无法抹掉 Elasticsearch 与 Hive 集成 实时消费 MySQL Binlog 2020阴霾之下
多个 git 账户配置 SSH
时光机 · 2020-12-26 · via TimeMachine Notes

前言

个人代码维护在 github,而目前大多数公司代码维护在私有 gitlab。这是两套不同的账户体系,并且一般私有 gitlab 的 commit email 不能更改,git 全局的用户名和邮箱只能有一个。这就导致了如下问题 → 不管配置了几个 SSH pub key,SSH 认证最终走的都是 global 的用户名的认证(比如你全局的用户是 github 的,那么你提交 gitlab 就会报 Permission Denied)。本文主要用来解决此问题。
其实多个 SSH 配置的话都是这样搞的,配个路由就好了。

配置 SSH

github

生成 ssh pub key,并将其添加到 github settings 的 SSH 配置中。

1
ssh-keygen -t rsa -C '${your github emial}' -f github

gitlab

生成 ssh pub key,并将其添加到 gitlab settings 的 SSH 配置中。

1
ssh-keygen -t rsa -C '${your gitlab emial}' -f gitlab

SSH config

修改 ssh 配置文件,用来配置不同 host 下用的 SSH 验证文件是哪个。可以理解为路由,发的请求都会查阅此文件来确定验证的 key 是哪个。

1
2
3
4
5
6
7
8
9
10
Host gitlab
HostName git.zuoyebang.cc
User zhanghailiang01
IdentityFile ~/.ssh/gitlab


Host github.com
HostName github.com
User xxx
IdentityFile ~/.ssh/github

验证

验证配置好的 SSH 是否可用

1
2
3
4
5
$ ssh -T git@gitlab
Welcome to GitLab, @xxx!

$ ssh -T [email protected]
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.

使用

经过上步验证通过后,免密提交 gitlab 还有一定的问题。我们还需要修改对应 gitlab 项目的用户名和邮箱,因为我们提交代码的账户认证是这个,而不是 git 全局的用户。修改完成之后,可以查看对应项目下的 .git/config 文件是否修改成功。

1
git config --local user.name 'xxx' && git config --local user.email '[email protected]'

对于以后新增的 gitlab 项目,都要执行此步。