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

推荐订阅源

L
LINUX DO - 热门话题
Stack Overflow Blog
Stack Overflow Blog
B
Blog
WordPress大学
WordPress大学
Project Zero
Project Zero
P
Palo Alto Networks Blog
阮一峰的网络日志
阮一峰的网络日志
博客园 - 司徒正美
有赞技术团队
有赞技术团队
S
SegmentFault 最新的问题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
小众软件
小众软件
T
Tailwind CSS Blog
Forbes - Security
Forbes - Security
F
Full Disclosure
SecWiki News
SecWiki News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Hacker News: Ask HN
Hacker News: Ask HN
C
Check Point Blog
Microsoft Security Blog
Microsoft Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
F
Fortinet All Blogs
Cisco Talos Blog
Cisco Talos Blog
G
Google Developers Blog
J
Java Code Geeks
Google DeepMind News
Google DeepMind News
人人都是产品经理
人人都是产品经理
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recorded Future
Recorded Future
O
OpenAI News
Spread Privacy
Spread Privacy
MongoDB | Blog
MongoDB | Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
C
Cybersecurity and Infrastructure Security Agency CISA
S
Securelist
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
IT之家
IT之家
U
Unit 42
腾讯CDC
S
Security Affairs
C
Cisco Blogs
Schneier on Security
Schneier on Security
The Last Watchdog
The Last Watchdog
B
Blog RSS Feed
宝玉的分享
宝玉的分享
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security @ Cisco Blogs
Cyberwarzone
Cyberwarzone
T
The Blog of Author Tim Ferriss

Tevin Zhang |

修复群晖 WebDAV 的 CORS 问题,不改 Nginx 独立开发者的开发者市场陷阱 我如何管理了 12 年的笔记 家用小型管理交换机对比 不要把企业当人看 在 Yunohost 上备份 crontabs 联邦宇宙平台评估 在 Jekyll 中使用 “details” 元素 数据存储与文明的衰落
在OpenBSD上进行私有Git托管
Tevin Zhang · 2023-10-05 · via Tevin Zhang |
  • 2023-12-11: 添加了第二种 clone 方式

多年来,我一直在自托管的Gogs服务器上托管我的个人Git仓库。尽管一些小问题一直存在,但我一直忍受着,直到最近。在再次 push 时发生了500错误后,我终于决定是时候迁移到一个更可靠的平台了。

我决定尝试Gitea,希望它能带来一些稳定性以及我一直渴望的代码搜索功能。

虽然我没有使用像问题和合并请求等功能,但迁移并不容易,我设法使用一个修改版本的 Perl 迁移脚本成功迁移了大多数仓库。由于在迁移过程中Gitea出现了各种错误,其他仓库必须以非常手动的方式迁移。

当我最终迁移了所有仓库时,我发现Gitea上的一些仓库是空的,而它们在Gogs上的原始仓库不是空的。这些仓库是第一批迁移,Gitea声称已成功迁移,我找出了问题并成功迁移了那些空的仓库。

此时,我的迁移已完全完成,Gitea正与我以前的所有仓库一起工作。然而,Gitea给我的虚假阳性1是不可接受的,如果我相信了它们,可能会导致数据丢失,对于Git仓库,数据完整性始终是第一位的。

最后,我销毁了刚刚迁移到的Gitea实例,并将所有仓库通过SSH迁移到了一个原始的OpenBSD服务器上,这简单、有效且非常稳定,下面是具体步骤。

先决条件

  • 启用 sshd(8)2
  • 安装 git (pkg_add git)
  • 设置 doas(1)(查看 doas.conf(5))或修改命令以不使用它

配置服务器

创建git用户

即使您是唯一访问这些仓库的人,也提供了更多的安全性和隔离,通常是需要的。

# mkdir -p /home/git
# user add git
# chown -R git:git /home/git

限制用户

git-shell(1)git(1) 一起提供,是专门用于Git-Only SSH访问的受限登录Shell。

将这个Shell设置为git用户的默认Shell:

# chsh git -s $(which git-shell)

将以下内容添加到 /etc/ssh/sshd_config 以限制git用户的某些SSH功能,确保它不能通过SSH执行潜在的风险操作。

Match User git
	AllowAgentForwarding no
	AllowTcpForwarding no
	X11Forwarding no
	PermitTTY no

创建仓库

doas -u git git init --bare /home/git/test.git

这会初始化git配置,以便为该仓库计划定时维护任务。

doas -u git GIT_DIR=/home/git/test.git git maintanence register

结果保存在 /home/git/.gitconfig

[maintenance]
	repo = /home/git/test.git

启动定时维护任务

只需运行一次,在 cron 中安装定期维护任务

# doas -u git GIT_DIR=/home/git/test.git git maintanence start

使用以下命令查看添加的 cron 任务:

添加的任务大概长这样

# BEGIN GIT MAINTENANCE SCHEDULE
# The following schedule was created by Git
# Any edits made in this region might be
# replaced in the future by a Git command.

0 1-23 * * * "/usr/local/libexec/git/git" --exec-path="/usr/local/libexec/git" for-each-repo --config=maintenance.repo maintenance run --schedule=hourly
0 0 * * 1-6 "/usr/local/libexec/git/git" --exec-path="/usr/local/libexec/git" for-each-repo --config=maintenance.repo maintenance run --schedule=daily
0 0 * * 0 "/usr/local/libexec/git/git" --exec-path="/usr/local/libexec/git" for-each-repo --config=maintenance.repo maintenance run --schedule=weekly

# END GIT MAINTENANCE SCHEDULE

在客户端

克隆仓库

# git clone git@your.domain:test.git

对于位于 /home/git/folder/repo.git 下的仓库

# git clone git@your.domain:folder/repo.git

注意: 这是一个类 scp 语法, 因此不用加 ssh://.

或者

# git clone ssh://git@your.domain:/~/folder/repo.git

剩下的你知道了

下一步

  • 如果还没有,请为 /home/git 设置备份
  • /home/git/git-shell-commands 下创建自定义脚本3 以执行常见的仓库操作,如CRUD
  • 如果需要公共访问,或者需要Web UI,设置 git-daemon(1)giweb(1)cgit
  1. https://mastodon.tevinzhang.com/@tevin/111129696403308201?utm_source=tevinzhang.com

  2. Git 官方文档在 SSH 和 HTTPS 之间多次反复变更了建议的协议. 对我而言,SSH 更容易配置, 更安全并且性能更高。 ↩

  3. 我目前实现了 helpadd_keylsmkrepo(包括维护任务的注册) 和 rm (基于 trash(1)) ↩