From 4a890dad70bed4fa158f0607ee44fa5f02502b9c Mon Sep 17 00:00:00 2001
From: Charles Cabergs Every repository on the server will be owned by a git user. Create a new directory to store the repositories owned by the git user. Login as the git user so the new repositories will be owned by him. They will be stored as bare, meaning we will only store the Or clone a distant one: Look at the content of a bare repository and the How to make your own git server/website
Basic ssh server
useradd -m gituseradd -m gitmkdir /srv/git
-chown git:git /srv/gitmkdir /srv/git
+chown git:git /srv/gitsu git
-cd /srv/gitsu git
+cd /srv/gitCreating a repository
.git folder not the actual files (called the workspace) to save space.
It’s a convention to to suffix a bare repository with the .git extension.mkdir repo.git
-cd repo.git
-git init --baremkdir repo.git
+cd repo.git
+git init --baregit clone --bare <location>git clone --bare <location>
@@ -38,26 +38,26 @@ It’s a convention to to suffix a bare repository with the .git directory in a regular one to convince yourself that they’re the same..git ex
Follow the steps and it will create id_rsa (private key) and id_rsa.pub (public key) in ~/.ssh.
On your server you append your public key to /home/git/.ssh/authorized_keys
At this point you should be able to login as the git user via ssh
-ssh git@<host>ssh git@<host>You can clone from your server.
-git clone git@<hostname>:/srv/git/<reponame>.gitgit clone git@<hostname>:/srv/git/<reponame>.gitPermitting the git user to have a regular shell can be too permissive, we would like to restrict him to a few repository actions, like creation/deletion, importing (clone), listing.
-echo $(which git-shell) >> /etc/shells` # Register the git-shell as a valid shell
-chsh -s $(which git-shell) git # Change the shell of the git userecho $(which git-shell) >> /etc/shells` # Register the git-shell as a valid shell
+chsh -s $(which git-shell) git # Change the shell of the git userIf you try to ssh as the git user, you will be greeted with something along the line of:
fatal: Interactive git shell is not enabled.
hint: ~/git-shell-commands should exist and have read and execute access.
Connection to <host> closed.
As suggested by the hint we have to create the directory /home/git/git-shell-commands and put the commands (executable) available to the git user.
#!/bin/sh
-[ $# -ne 1 ] &&
- echo "Usage: $0 repository" && exit 1
-repo_path="/srv/git/$1.git"
-[ -d "$repo_path" ] &&
- echo "$0: Error: $repo_path already exist" && exit 2
-mkdir "$repo_path"
-git -C "$repo_path" init --bare#!/bin/sh
+[ $# -ne 1 ] &&
+ echo "Usage: $0 repository" && exit 1
+repo_path="/srv/git/$1.git"
+[ -d "$repo_path" ] &&
+ echo "$0: Error: $repo_path already exist" && exit 2
+mkdir "$repo_path"
+git -C "$repo_path" init --bareThis script create a new repository in /srv/git.
Put it under git-shell-commands/create and make it executable then try to ssh as the git user once again.
You will be prompted with git>, you can only execute the create <repository> and exit command.
help script, it will be ran at the beginning of the co
Cloning with ssh is fine but only the people with ssh access can do it, we would like anyone to clone.
git-daemon does precisely that, after running it you will be able to run git clone git://<host>/<repository>
git daemon --reuseaddr --base-path=/srv/git/ /srv/git/git daemon --reuseaddr --base-path=/srv/git/ /srv/git/Follow the instruction of this tutorial if you want to know how to make it a service
You may want to introduce a public/private distinction for your repositories.
@@ -118,24 +118,24 @@ make install
Git hooks are scripts located in <repository>/.git/hooks that will be run on a certain action.
The hook we’re interested in is post-receive, it will be ran after someone pushes to the repository.
We can use it to regenerate the repository’s pages and the website’s index.
#!/bin/sh
-
-# Insert repo_name variable here
-# <REPO_NAME> -- replace with repo_name=name
-
-[ -z "$repo_name" ] && exit 1
-[ ! -d "/srv/git/public/$repo_name.git" ] && exit
-
-repo_web_path="/var/www/git/$repo_name"
-mkdir -p "$repo_web_path"
-cd "$repo_web_path" || exit 1
-stagit "/srv/git/$repo_name.git"
-stagit-index /srv/git/public/* > /var/www/git/index.html#!/bin/sh
+
+# Insert repo_name variable here
+# <REPO_NAME> -- replace with repo_name=name
+
+[ -z "$repo_name" ] && exit 1
+[ ! -d "/srv/git/public/$repo_name.git" ] && exit
+
+repo_web_path="/var/www/git/$repo_name"
+mkdir -p "$repo_web_path"
+cd "$repo_web_path" || exit 1
+stagit "/srv/git/$repo_name.git"
+stagit-index /srv/git/public/* > /var/www/git/index.htmlThis is a template for the post-receive hook. Every time you publish a repository you can change his post-receive hook.
post_receive_path="<repository>/hooks/post-receive"
-sed '/REPO_NAME/ c repo_name='"$repo" < post-receive.template > "$post_receive_path"
-chmod +x "$post_receive_path"
-"$post_receive_path"post_receive_path="<repository>/hooks/post-receive"
+sed '/REPO_NAME/ c repo_name='"$repo" < post-receive.template > "$post_receive_path"
+chmod +x "$post_receive_path"
+"$post_receive_path"-- cgitAdd this code to your
publishscript