Hosting Git repositories, The Easy (and Secure) Way

【Claude Code · VibeCoding】03|环境:Git 与 Node.js 安装 本地先装好 Git 与 Node.js,后面才能装 Claude Code CLI。按课件截图完成安装与版本检查。 阅读详情

Hosting Git repositories, The Easy (and Secure) Way

8/24/2009 11:45:25 PM

http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way

 

Hosting Git repositories, The Easy (and Secure) Way

Posted: November 14, 2007, by garry
Tags: git hosting

Update (08-10-2008): For topics not covered here, I encourage everyone to read the gitosis README, bundled with the distribution. There is also an example.conf configuration file that illustrates more features than I have covered here.

I have been asked more and more these days, "How do I host a Git repository?" Usually it is assumed that some access control beyond simply read-only is involved (some users have commit rights). With access control comes issues of security, and that's a whole other bag of cats. This post is about presenting an answer to this question, without the fuss.

The rest of this article will be a tutorial showing you how to host and manage Git repositories with access control, easily and safely. I use an up and coming tool called gitosis that my friend Tv wrote to help make hosting git repos easier and safer. It manages multiple repositories under one user account, using SSH keys to identify users. However, users do *not* need shell accounts on the server, instead they will talk to one shared account that does not allow arbitrary commands. Git itself is used to setup gitosis and manage the Git repos, which pleases the recursion-seeking orthogonal CS-side of my brain.

Assumptions: I take my examples from a Ubuntu Linux server. While I haven't tested other systems, I imagine different Linux distributions, FreeBSD, OS X, etc... would be similar. Gitosis is written in Python, so you should have a copy of Python installed as well.

Enough talk, let's get down and dirty.

Install gitosis

gitosis is a tool for hosting git repositories (I'm repeating myself for those who skim :)

The first thing to do is grab a copy of gitosis and install it on your server:

 

cd ~/src
git clone git://eagain.net/gitosis.git

 

Notice that gitosis is extremely light-weight. The clone takes a mere couple seconds. Less is more, and I like that a lot.

Next, install it like so:

 

cd gitosis
python setup.py install

 

Don't use --prefix unless you like self-inflicted pain. It is possible to install gitosis in a non-standard location, but it's not nice. Read the Caveats section at the bottom and then come back here.

If you get this error:

 

-bash: python: command not found

 

or

 

Traceback (most recent call last):
  File "setup.py", line 2, in ?
    from setuptools import setup, find_packages
ImportError: No module named setuptools

 

You have to install Python setuptools. On Debian/Ubuntu systems, it's just:

 

sudo apt-get install python-setuptools

 

For other systems, someone tell me or leave a comment, so I can update this section and improve this tutorial.

The next thing to do is to create a user that will own the repositories you want to manage. This user is usually called git, but any name will work, and you can have more than one per system if you really want to. The user does not need a password, but does need a valid shell (otherwise, SSH will refuse to work).

 

sudo adduser /
    --system /
    --shell /bin/sh /
    --gecos 'git version control' /
    --group /
    --disabled-password /
    --home /home/git /
    git

 

You may change the home path to suit your taste. A successful user creation will look similar to:

 

Adding system user `git'...
Adding new group `git' (211).
Adding new user `git' (211) with group `git'.
Creating home directory `/home/git'.

 

You will need a public SSH key to continue. If you don't have one, you may generate one on your local computer:

 

ssh-keygen -t rsa

 

The public key will be in $HOME/.ssh/id_rsa.pub. Copy this file to your server (the one running gitosis).

Next we will run a command that will sprinkle some magic into the home directory of the git user and put your public SSH key into the list of authorized keys.

 

sudo -H -u git gitosis-init < /tmp/id_rsa.pub

 

id_rsa.pub above is your public SSH key that you copied to the server. I recommend you put it in /tmp so the git user won't have permission problems when trying to read it. Success looks like:

 

Initialized empty Git repository in ./
Initialized empty Git repository in ./

 

(Yes, two times)

For good measure, let's make sure the post-update hook is set executable. I've seen it where sometimes it doesn't get set (problem with older setuptools):

 

sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update

 

Here some cool magic happens. Run this on your local machine:

 

git clone git@YOUR_SERVER_HOSTNAME:gitosis-admin.git
cd gitosis-admin

 

You will now have a gitosis.conf file and keydir/ directory:

 

~/dev/gitosis-admin (master) $ ls -l
total 8
-rw-r--r--   1 garry  garry  104 Nov 13 05:43 gitosis.conf
drwxr-xr-x   3 garry  garry  102 Nov 13 05:43 keydir/

 

This repository that you just cloned contains all the files (right now, only 2) needed to create repositories for your projects, add new users, and defined access rights. Edit the settings as you wish, commit, and push. Once pushed, gitosis will immediately make your changes take effect on the server. So we're using Git to host the configuration file and keys that in turn define how our Git hosting behaves. That's just plain cool.

From this point on, you don't need to be on your server. All configuration takes place locally and you push the changes to your server when you're ready for them to take effect.

Creating new repositories

This is where the fun starts. Let's create a new repository to hold our project codenamed FreeMonkey.

Open up gitosis.conf and notice the default configuration:

 

[gitosis]                  

[group gitosis-admin]
writable = gitosis-admin
members = jdoe                     

 

Your "members" line will hold your key filename (without the .pub extension) that is in keydir/. In my example, it is "jdoe", but for you it'll probably be a combination of your username and hostname.

To create a new repo, we just authorize writing to it and push. To do so, add this to gitosis.conf:

 

[group myteam]
members = jdoe
writable = free_monkey

 

This defines a new group called "myteam", which is an arbitrary string. "jdoe" is a member of myteam and will have write access to the "free_monkey" repo.

Save this addition to gitosis.conf, commit and push it:

 

git commit -a -m "Allow jdoe write access to free_monkey"
git push

 

Now the user "jdoe" has access to write to the repo named "free_monkey", but we still haven't created a repo yet. What we will do is create a new repo locally, and then push it:

 

mkdir free_monkey
cd free_monkey
git init
git remote add origin git@YOUR_SERVER_HOSTNAME:free_monkey.git

# do some work, git add and commit files

git push origin master:refs/heads/master

 

With the final push, you're off to the races. The repository "free_monkey" has been created on the server (in /home/git/repositories) and you're ready to start using it like any ol' git repo.

Adding users

The next natural thing to do is to grant some lucky few commit access to the FreeMonkey project. This is a simple two step process.

First, gather their public SSH keys, which I'll call "alice.pub" and "bob.pub", and drop them into keydir/ of your local gitosis-admin repository. Second, edit gitosis.conf and add them to the "members" list.

 

cd gitosis-admin
cp ~/alice.pub keydir/
cp ~/bob.pub keydir/
git add keydir/alice.pub keydir/bob.pub

 

Note that the key filename must have a ".pub" extension.

gitosis.conf changes:

 

 [group myteam]
- members = jdoe
+ members = jdoe alice bob
  writable = free_monkey

 

Commit and push:

 

git commit -a -m "Granted Alice and Bob commit rights to FreeMonkey"
git push

 

That's it. Alice and Bob can now clone the free_monkey repository like so:

 

git clone git@YOUR_SERVER_HOSTNAME:free_monkey.git

 

Alice and Bob will also have commit rights.

Public access

If you are running a public project, you will have your users with commit rights, and then you'll have everyone else. How do we give everyone else read-only access without fiddling w/ SSH keys?

We just use git-daemon. This is independent of gitosis and it comes with git itself.

 

sudo -u git git-daemon --base-path=/home/git/repositories/ --export-all

 

This will make all the repositories you manage with gitosis read-only for the public. Someone can then clone FreeMonkey like so:

 

git clone git://YOUR_SERVER_HOSTNAME/free_monkey.git

 

To export only some repositories and not others, you need to touch git-daemon-export-ok inside the root directory (e.g. /home/git/repositories/free_monkey.git) of each repo that you want public. Then remove "--export-all" from the git-daemon command above.

More tricks

gitosis.conf can be set to do some other neat tricks. Open example.conf in the gitosis source directory (where you originally cloned gitosis way at the top) to see a summary of all options. You can specify some repos to be read-only (opposite of writable), but yet not public. A group members list can include another group. And a few other tricks that I'll leave it to the reader to discover.

Caveats

If /home/git/.gitosis.conf on your server never seems to get updated to match your local copy (they should match), even though you are making changes and pushing, it could be that your post-update hook isn't executable. Older versions of setuptools can cause this. Be sure to fix that:

 

sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update

 

If your Python goodies are in a non-standard location, you must additionally edit post-update and put an "export PYTHONPATH=..." line at the top. Failure to do so will give you a Python stack trace the first time you try to push changes within gitosis-admin.

If you want to install gitosis in a non-standard location, I don't recommend it. It's an edge case that the author hasn't run up against until I bugged him to help me get it working.

For the brave, you need to edit whatever file on your system controls the default PATH for a non-login, non-interactive shell. On Ubuntu this is /etc/environment. Add the path to gitosis-serve to the PATH line. Also insert a line for PYTHONPATH and set it to your non-standard Python site-packages directory. As an example, this is my /etc/environment:

 

PATH="/home/garry/sys/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games"
PYTHONPATH=/home/garry/sys/lib/python2.4/site-packages

 

Be sure to logout and log back in after you make these changes.

Don't use the gitosis-init line I have above for the standard install, instead use this slightly modified one:

 

sudo -H -u git env PATH=$PATH gitosis-init < /tmp/id_rsa.pub

 

Be sure to also set PYTHONPATH in your post-update hook as described above.

The *should* do it. I am purposefully terse with this non-standard setup as I think not many people will use it. HIt me up in #git on FreeNode if you need more info (my nick is up_the_irons).

 

Non-standard SSH port

If you run SSH on a non-standard port on your server, don't use the syntax "git@myserver.com:1234:/foo/bar", it won't work. Putting the port in the URL doesn't seem to make gitosis, or git, (not sure which) happy. Instead, put this in your ~/.ssh/config file:

Host myserver.com
  Port 1234

 

Conclusion

Well, I hope you enjoyed this tutorial and that it makes your Git hosting life easier. This is public revision 10. Please let me know if you find mistakes, omissions, an easier way than what I described, etc...

Git it on...

(yeah, that was bad...)

http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way
Jetson Nano官方镜像下载&烧录 在NVIDIA Jetson Nano开发者套件上安装NVIDIA官方Ubuntu镜像 阅读详情

相关推荐

FreeSurfer预处理命令

比如将/source/kernel.tgz解压到 /source/linux-2.6.29 目录 tar zxvf /source/kernel.tgz -C /source/ linux-2.6.29 tar zxvf /home/tj/application/freesurfer/subjects/mindboggle/OASIS-TRT-20-1.tar.gz -C /home/tj/application/freesurfer/subjects (1)lh.thickness mri_surf2su

Dream19961996的博客 1506

[转]Hosting Git repositories, The Easy (and Secure) Way

Hosting Git repositories, The Easy (and Secure) WayPosted: November 14, 2007, by garryTags: git hosting Update (08-10-2008): For topics not covered here, I encourage everyone to read the gitos

Fly的专栏 954

ArcGIS-裁剪遥感影像及dem图像

6、选择【工具箱】-【数据管理工具】-【栅格】-【裁剪】。在【输入栅格】里选择要裁剪的dem,在【输出范围】里选择刚创建的裁剪范围。选择一个输出路径,其他参数保存默认。2、起一个名称,要素类型选择【面】。点击【编辑】选择与要裁剪的dem一致的地理坐标系。1、创建需要裁剪区域的面层shp,右击选择【新建】-【shapefile】3、点击编辑器,选择开始编辑。4、选择【裁剪范围】,点击确定。5、画出想要裁剪的范围并保存。

siwenaiyou的博客 1万+

github付费吃亏记

做开源项目用github当然是首选,我习惯了github实在很不愿意回到老旧的svn上面,因此打算在非开源项目中也使用github的收费服务private repository来做SCM。github有各种付费服务项目,http://github.com/plans,从$7 per month ~ $20,000 per year的企业级服务一应俱全,看起来相当酷。   于是今天我购买了$7...

hulefei29的专栏 524

菲涅尔波带片

菲涅尔波带片的简介,以及matlab绘制

Bestchinese的博客 1万+

携程登录风控逆向踩坑实录:从滑块到点选验证码,我是如何一步步拿到phantom-token的

本文详细解析了携程登录风控系统的逆向过程,从滑块验证码到点选验证码的破解,再到设备指纹生成和加密协议逆向,最终成功获取phantom-token。文章提供了关键代码示例和实战技巧,帮助开发者理解并绕过复杂的风控机制。

weixin_28049429的博客 970

工作中使用到的单词(软件开发)

1.エイリアス   alias 别名 powershell使用 get-help 命令时,会得到与此命令 相关(别名)的命令 2.プロキシ proxy 代 理 3.プロモート   promote 促进,提升   开发的系统新功能上线发布,有时会使用到这个词,比如 STプロモート 还有使用リリース这个词的。比如STリリース。个人认为两者含义相同。 4.見逃し み................................................................

sun0322 6万+

手教你如何使用Simulink和相关工具箱模拟和实现无人机的多机接力信号中继的建模

扩大通信范围:单架无人机的通信能力有限,通过多机接力的方式可以显著扩展通信覆盖范围。提高可靠性:当某架无人机出现故障或电量不足时,其他无人机可以接管其任务,确保通信不中断。适应复杂环境:在山区、森林等复杂地形中,多机接力可以绕过障碍物,建立稳定的通信链路。使用Communications Toolbox中的模块来模拟无线通信链路。例如,可以使用模块模拟噪声信道,或者使用模块计算信号衰减。matlab深色版本。

MHD0815的博客 767

让 AI 替我操作这台电脑,先把手能伸多远定下来

早上坐到工位,才想起昨天那份表格还在家里的机器上。这种时候以前只有两条路,开远程桌面自己点,或者等晚上回去。热榜上那篇 OpenClaw 的实测文我看了两遍。它换掉的是这条路。在 Windows 上装一个网关,把飞书、钉钉、Telegram 这些入口接进来,模型听懂你那句话,网关在本机上真的动手。装 Node 22 和 Git,跑一条,选一个 OpenAI 兼容的供应商把 base url 和 key 填上,再接远程访问,手机发一句话,家里那台电脑就开始干活。那篇文把部署讲了很细,截图一步一步都有。

m0_58155849的博客 363

Codex 实战 Skills:用 Skill 自动识别并提取 PDF/图片表格数据,效率提升 10 倍

本文介绍如何构建一个多模态文件解析 Skill,用于自动识别和提取 PDF/图片中的表格数据,提升 AI 智能体处理非结构化文档的效率。文章分析了传统方法的局限性,提出分层解析架构(预处理、检测、提取推理、后处理),推荐技术栈包括 pdfplumber、OpenCV 和多模态大模型。详细说明了 Skill 的元数据定义、数据模型设计(使用 Pydantic)和核心实现流程,通过混合策略实现从复杂文档到结构化 JSON/Markdown 的转换,使 AI 代理具备"阅读"多模态文档的能力。

yueyeguzhuo的专栏 302

【30】软考软件设计师——UML类图与用例图满分精讲|下午第3题常考核心

本文是《软件设计师·50讲通关|从零基础到工程师职称》专栏第30篇,聚焦**模块四:应用技术(下午题)第3道高频大题**,UML建模是历年下午必考核心,单题分值稳定10~12分。全文深度拆解两大核心UML图表:**类图**与**用例图**,超详细讲解类图三层结构、可见性修饰符、五大核心关系(泛化/关联/依赖/聚合/组合)的判定标准与绘图规范;吃透用例图参与者、系统边界、三大关系(包含/扩展/泛化)的底层逻辑,搭配独家**关系秒杀口诀、标准绘图模板、真题改错技巧**;全文适配补图、判断关系、分析场景、纠错优化

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 572

[LLM Wiki理论与实践-05]解读OpenWiki的Personal模式构建的知识库目录结构

[LLM Wiki理论与实践-04:使用OpenWiki的Personal模式构建知识库]介绍了如何执行安装OpenWiki和通过执行`openwiki personal --init`命令以个人模式进行初始化,最终调用`openwiki personal --update`和`openwiki ingest`命令利用配置的Connector加载外部数据源来生成构建个人知识库的Wiki页。这篇文章我们就来看看采用OpenWiki的Personal模式构建的知识库对应目录的结构以及具体文件的内容。

JaydenAI的博客 301

YOLOv5改进 | 注意力篇 | iRMB倒置残差块注意力机制(轻量化注意力机制,附二次创新)

本文给家大家带来的改进机制是iRMB,其是在论文Rethinking Mobile Block for Efficient Attention-based Models种提出,论文提出了一个新的主干网络EMO(后面我也会教大家如何使用该主干,本文先教大家使用该文中提出的注意力机制)。其主要思想是将轻量级的CNN架构与基于注意力的模型结构相结合(有点类似ACmix)我将iRMB和C2f结合,然后也将其用在了检测头种进行尝试三种结果进行对比,针对的作用也不相同,但是无论那种实验均有一定涨点效果。

Snu77的博客 2570

AI行业日报|2026-11-03:5个热点事件

本期内容覆盖基础模型安全边界演进、数据版权合规诉讼、预测型世界模型架构、AI原生工程基础设施升级及自动化代码审查链路优化。以下信息严格依据公开技术报告与权威媒体披露整理,已按证据来源逐条锚定,未经验证的具体实现细节均已归入架构建议区块,供工程团队对照实施。 Anthropic 发布技术预警,指出其当前模型训练循环已非常接近递归自我改进(Recursive Self-Improvement, RSI)阈值,即行业内所称的“自主构建AI”状态 1 。RSI 指代模型在训练与...

2504_94201249的博客 226

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

自建 Git 服务器和裸仓库差在哪:要能提合并请求

在一台 Linux 上 git init --bare 就能自建 Git 服务器,但它只能推拉代码,没有网页、合并请求、评审和按仓库分配的权限。对照裸仓库和 AngusGit 各自能做什么,再走一遍在 AngusGit 上发起合并请求的最短路径,以及已有裸仓库怎么完整搬过来。

AngusTester 318

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

【Git】从入门到精通(十)—— 撤销与恢复:git checkout与git restore

本文系统讲解Git中撤销与恢复的核心命令,重点对比git checkout与新命令git restore的使用场景。针对“改错、add错、提交错”等常见问题,提供清晰解决方案:未暂存修改用git restore <file>,误暂存用git restore --staged,历史版本恢复用--source。强调git restore语义更清晰,推荐优先使用。同时提醒撤销操作不可逆,建议先git status、git diff确认,不确定时用git stash保底。最后总结速查表,帮助初学者安全高

m0_67393827的博客 460

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

重装 openvino、yaml-cpp

【代码】重装 yaml-cpp。

u010948546的博客 217

Git 新手使用教程

面向零基础用户的 Git 入门指南:从安装到日常使用,覆盖 90% 的常见场景。

Jerry小杰 228

Claude Code做Unity项目移植(三): 使用SKILL进行自动化Git提交

本文介绍基于ClaudeCodeSkill的Unity自动化Git提交助手——unity-git-commit,通过四大模块实现提交前的智能检查与安全修复:1)校验Git仓库状态;2)验证Unity项目文件(如排除Library/Temp,确保.meta文件完整);3)依据可配置的C#命名规范自动识别并安全修复命名问题(避免序列化、反射等高危场景误改);4)生成精准提交注释,但强制人工确认。全程仅本地commit,不自动推送或破坏性操作,保障安全。核心思想为“机械化工作交AI,关键决策留人工”,显著提升提交

Aman1984的博客 641

【Git】从入门到精通(九)—— git diff:查看文件差异

本文全面解析Git的gitdiff命令,详解其三大核心场景:工作区vs暂存区、暂存区vs版本库、工作区vs版本库,涵盖输出格式、常用选项(如--stat、--name-only、-w)、版本比较、文件差异及外部工具集成。通过实战案例演示代码审查、提交自查、调试定位等应用场景,强调gitdiff--staged作为提交前检查的关键作用,并总结记忆口诀与常见问题解决方案,助力开发者精准掌握代码变更细节。

m0_67393827的博客 283

Hive的多机 AI Agent 协同看板实战:跨机留言、任务搁置、计划跟踪的三个设计取舍

本文介绍多机AI Agent协同系统Hive的三项关键设计取舍:跨机留言采用内存+本地文件存储,避免Git版本冲突与延迟;搁置状态主动释放资源并保留历史,通过按钮而非新增列管理,保持看板简洁;任务计划以Tab形式聚合任务,实现项目级进度追踪。核心原则是“能用文件解决就不加数据库,能复用界面就不新增层级”,所有功能均在零依赖前提下实现高可用与易用性。附带一次/api/plans 404排查,揭示了配置与路由匹配的深层陷阱,具有普遍参考价值。

skywalk8163的专栏 531

中国 DevSecOps 领导者:Gitee 在金融级研发平台中的实践与定位

在 DevSecOps 语境下,领导者通常指在代码托管、持续集成、安全测试左移与研发流程治理四个环节中,能提供一体化平台能力并在关键行业形成规模化落地的服务商。据 Gitee 内部产品资料,Gitee 将 DevSecOps 敏捷安全列为技术应用场景之一,并配套 AST 全流程安全测试与开源风险治理能力。评估这类平台时,技术决策者应重点关注五个维度:私有化部署能力、信创兼容性、金融级客户案例、历史数据迁移路径、以及与现有身份认证体系的集成深度。

2602_96414767的博客 224

热榜上手|HyperFrames:写HTML出MP4

HeyGen 开源的 TypeScript 视频框架:把 HTML、CSS 动画直接渲染成确定性 MP4,专为 AI agent 批量出片设计,单周涨 5633 star。

mihuyang的博客 254

WSL 中 Git Clone GitHub 仓库完整踩坑指南

问题最佳解法WSL 证书验证失败或重装 ca-certificates22 端口超时SSH 走缺少密钥+ 添加到 GitHub权限过宽被拒Gitee 认证失败使用 PAT 替代密码 + 清除凭据缓存--system权限拒绝改用--global或--local作用域一条黄金建议:在 WSL 中访问 GitHub,优先使用 SSH over 443。一次配置,永久解决证书、端口、认证三重问题,比 HTTPS 方式稳定得多。

dingyuana的专栏 353
上一篇: Git起步
下一篇: 《看日记学git》之随笔笔记
gracioushe
博客等级 码龄25年 62粉丝 98原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值