source: general/prog/gitserver.xml@ 29d3017a

10.1 11.0 11.1 11.2 11.3 12.0 12.1 kea ken/TL2024 ken/inkscape-core-mods ken/tuningfonts lazarus lxqt plabs/newcss plabs/python-mods python3.11 qt5new rahul/power-profiles-daemon renodr/vulkan-addition trunk upgradedb xry111/intltool xry111/llvm18 xry111/soup3 xry111/test-20220226 xry111/xf86-video-removal
Last change on this file since 29d3017a was 29d3017a, checked in by Thomas Trepl <thomas@…>, 3 years ago

Fix sed for password hash

git-svn-id: svn://svn.linuxfromscratch.org/BLFS/trunk/BOOK@24103 af4574ff-66df-0310-9fd7-8a98e5e911e0

  • Property mode set to 100644
File size: 13.7 KB
Line 
1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
4 <!ENTITY % general-entities SYSTEM "../../general.ent">
5 %general-entities;
6 <!ENTITY gitgid "58">
7 <!ENTITY gituid "58">
8]>
9
10<sect1 id="gitserver" xreflabel="Running a Git Server">
11 <?dbhtml filename="gitserver.html"?>
12
13 <sect1info>
14 <othername>$LastChangedBy$</othername>
15 <date>$Date$</date>
16 </sect1info>
17
18 <title>Running a Git Server</title>
19
20 <sect2 role="package">
21 <title>Introduction</title>
22
23 <para>
24 This section will describe how to set up, administer and secure a
25 <application>git</application> server. <application>Git</application>
26 has many options available. For more detailed documentation see
27 <ulink url="https://git-scm.com/book/en/v2"/>.
28 </para>
29
30 <bridgehead renderas="sect3">Server Dependencies</bridgehead>
31
32 <bridgehead renderas="sect4">Required</bridgehead>
33 <para role="required">
34 <xref linkend="git"/> and
35 <xref linkend="openssh"/>
36 </para>
37
38 </sect2>
39
40 <sect2 role="configuration">
41 <title>Setting up a Git Server</title>
42
43 <para>
44 The following instructions will install a
45 <application>git</application> server. It will be set
46 up to use <application>OpenSSH</application> as the secure
47 remote access method.
48 </para>
49
50 <para>
51 Configuration of the server consists of the following steps:
52 </para>
53
54 <sect3>
55 <title>1. Setup Users, Groups, and Permissions</title>
56
57 <para>
58 You will need to be user <systemitem class='username'>root</systemitem>
59 for the initial portion of configuration. Create the <systemitem
60 class="username">git</systemitem> user and group and set and unusable
61 password hash with the following commands:
62 </para>
63
64<screen role="root"><userinput>groupadd -g &gitgid; git &amp;&amp;
65useradd -c "git Owner" -d /home/git -m -g git -s /usr/bin/git-shell -u &gituid; git &amp;&amp;
66sed -i '/^git:/s/^git:[^:]:/git:NP:/' /etc/shadow</userinput></screen>
67
68 <para>
69 Putting in an unuable password hash (replacing the <literal>!</literal>
70 by <literal>NP</literal>) unlocks the account but it cannot be used
71 to login via password authentication. That is required by
72 <application>sshd</application> to work properly.
73 Next, create some files and directories in the home directory of the git user
74 allowing access to the git repository using ssh keys.
75 </para>
76
77<screen role="root"><userinput>install -o git -g git -dm0700 /home/git/.ssh &amp;&amp;
78install -o git -g git -m0600 /dev/null /home/git/.ssh/authorized_keys</userinput></screen>
79
80 <para>
81 For any developer who should have access to the repository
82 add his/her public ssh key to <filename>/home/git/.ssh/authorized_keys</filename>.
83 First, prepend some options to prevent users from using the
84 connection to git for port forwarding to other machines
85 the git server might reach.
86 </para>
87
88<screen role="nodump"><userinput>echo -n "no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty " >> /home/git/.ssh/authorized_keys &amp;&amp;
89cat &lt;user-ssh-key&gt; &gt;&gt; /home/git/.ssh/authorized_keys</userinput></screen>
90
91 <para>
92 It is also useful to set the default name of the initial branch
93 of new repositories by modifying the git configuration. As the
94 <systemitem class='username'>root</systemitem> user, run:
95 </para>
96
97<screen role="nodump"><userinput>git config --system init.defaultBranch trunk</userinput></screen>
98
99 <para>
100 Finally add the <filename>/usr/bin/git-shell</filename> entry to
101 the <filename>/etc/shells</filename> configuration file. This shell
102 has been set in the <systemitem class='username'>git</systemitem>
103 user profile and is to make sure that only git related actions
104 can be executed:
105 </para>
106
107<screen role="root"><userinput>echo "/usr/bin/git-shell" &gt;&gt; /etc/shells</userinput></screen>
108
109 </sect3>
110
111 <sect3>
112 <title>2. Create a git repository</title>
113
114 <para>
115 The repository can be anywhere on the filesystem. It is
116 important that the git user has read/write access to that
117 location. We use <filename class="directory">/srv/git</filename>
118 as base directory. Create a new <application>git</application>
119 repository with the following commands (as the
120 <systemitem class="username">root</systemitem> user):
121 </para>
122
123 <note>
124 <para>
125 In all the instructions below, we use <emphasis>project1</emphasis>
126 as an example repository name. You should name your repository
127 as a short descriptive name for your specific project.
128 </para>
129 </note>
130
131<screen role="root"><userinput>install -o git -g git -m755 -d /srv/git/project1.git &amp;&amp;
132cd /srv/git/project1.git &amp;&amp;
133git init --bare &amp;&amp;
134chown -R git:git .</userinput></screen>
135
136 </sect3>
137
138 <sect3>
139 <title>3. Populate the repository from a client system</title>
140
141 <note>
142 <para>
143 All the instructions in this section and the next should
144 be done on a user system, not the server system.
145 </para>
146 </note>
147
148 <para>
149 Now that the repository is created, it can be used by the
150 developers to put some files into it. Once the ssh key of
151 the user is imported to git's <filename>authorized_keys</filename>
152 file, the user can interact with the repository.
153 </para>
154
155 <para>
156 A minimal configuration should be available on the developer's
157 system specifying its user name and the email address.
158 Create this minimal config file on client side:
159 </para>
160
161<screen role="nodump"><userinput>cat &gt; ~/.gitconfig &lt;&lt;EOF
162[user]
163 name = &lt;users-name&gt;
164 email = &lt;users-email-address&gt;
165EOF</userinput></screen>
166
167 <para>
168 On the developer's machine, setup some files to be pushed
169 to the repository as the initial content:
170 </para>
171
172 <note>
173 <para>
174 The <emphasis>gitserver</emphasis> term used below
175 should be the host name (or ip address) of the git server.
176 </para>
177 </note>
178
179<screen role="nodump"><userinput>mkdir myproject
180cd myproject
181git init --initial-branch=trunk
182git remote add origin git@gitserver:/srv/git/project1.git
183cat &gt;README &lt;&lt;EOF
184This is the README file
185EOF
186git add README
187git commit -m 'Initial creation of README'
188git push --set-upstream origin trunk</userinput></screen>
189
190 <para>The initial content is now pushed to the server and
191 is available for other users. On the current machine, the
192 argument <literal>--set-upstream origin trunk</literal> is
193 now no longer required as the local repository is now
194 connected to the remote repository. Subsequent pushes
195 can be performed as
196 </para>
197
198<screen role="nodump"><userinput>git push</userinput></screen>
199
200 <para>
201 Other developers can now clone the repository and do
202 modifications to the content (as long as their ssh keys
203 has been installed):
204 </para>
205
206<screen role="nodump"><userinput>git clone git@gitserver:/srv/git/project1.git
207cd project1
208vi README
209git commit -am 'Fix for README file'
210git push</userinput></screen>
211
212 <note>
213 <para>
214 This is a very basic server setup based on
215 <application>OpenSSH</application> access. All developers are using
216 the <systemitem class="username">git</systemitem> user to perform
217 actions on the repository and the changes users are commiting can be
218 distiguished as the local user name (see
219 <filename>~/.gitconfig</filename>) is recorded in the
220 changesets.</para>
221 </note>
222
223 <para>
224 Access is restricted by the public keys added to git's
225 <filename>authorized_keys</filename> file and there is no
226 option for the public to export/clone the repository. To
227 enable this, continue with step 4 to set up the git server
228 for public read-only access.
229 </para>
230
231 </sect3>
232
233 <sect3 id="gitserver-init">
234 <title>4. Configure the Server</title>
235
236 <para>
237 The setup described above makes a repository available for
238 authenticated users (via providing the ssh public key file).
239 There is also a simple way to publish the
240 repository to unauthenticated users &mdash; of course without write
241 access.
242 </para>
243
244 <para>
245 The combination of access via ssh (for authenticated users) and
246 the export of repositories to unauthenticated users via the
247 daemon is in most cases enough for a development site.
248 </para>
249
250 <note>
251 <para>
252 The daemon will be reachable at port <literal>9418</literal>
253 by default. Make sure that your firewall setup allows
254 access to that port.
255 </para>
256 </note>
257
258 <para revision="sysv">
259 To start the server at boot time, install the git-daemon
260 bootscript included in the <xref linkend="bootscripts"/> package:
261 </para>
262
263 <indexterm zone="gitserver gitserver-init" revision="sysv">
264 <primary sortas="f-git">git</primary>
265 </indexterm>
266
267<screen role="root" revision="sysv"><userinput>make install-git-daemon</userinput></screen>
268
269 <para revision="systemd">
270 To start the server at boot time, install the
271 <filename>git-daemon.service</filename> unit from the
272 <xref linkend="systemd-units"/> package:
273 </para>
274
275 <indexterm zone="gitserver gitserver-init" revision="systemd">
276 <primary sortas="f-gitserve">gitserve</primary>
277 </indexterm>
278
279<screen role="root" revision="systemd"><userinput>make install-git-daemon</userinput></screen>
280
281 <para>
282 In order to allow <application>git</application> to export a
283 repository, a file named <filename>git-daemon-export-ok</filename>
284 is required in each repository directory on the server. The
285 file needs no content, just its existance enables, its absence
286 disables the export of that repository.
287 </para>
288
289<screen role="root"><userinput>touch /srv/git/project1.git/git-daemon-export-ok</userinput></screen>
290
291 <para revision="sysv">
292 The script to start the git daemon uses some default values
293 internally. Most important is the path to the repository
294 directory which is set to <filename class="directory">/srv/git</filename>.
295 In case you have for whatever reason created the repository in a
296 different location, you'll need to tell the boot script where the
297 repository is to be found. This can be achieved by creating a
298 configuration file named <filename>/etc/sysconfig/git-daemon</filename>.
299 This configuration file will be imported if it exists, meaning it is
300 optional. The file can look like:</para>
301<screen revision="sysv">
302# Begin /etc/sysconfig/git-daemon
303
304# Specify the location of the git repository
305GIT_BASE_DIR="/srv/git/"
306
307# Directories added to whitelist
308DFT_REPO_DIR="$GIT_BASE_DIR"
309
310# Add extra options which will appended to the 'git daemon'
311# command executed in the boot script
312GIT_DAEMON_OPTS=""
313
314# End /etc/sysconfig/git-daemon
315</screen>
316 <para revision="systemd">
317 Along with the <filename>git-daemon.service</filename> unit, a
318 configuration file named <filename>/etc/default/git-daemon</filename>
319 has been installed. Review this configuration file to match your
320 needs.
321 </para>
322
323 <para>
324 There are only three options to set in the configuration file:
325 <itemizedlist>
326 <listitem>
327 <para>
328 GIT_BASE_DIR=&lt;dirname&gt;
329 </para>
330 <para>Specify the location of the git repositories.
331 Relative paths used when accessing the daemon will
332 translated relative to this directory.
333 </para>
334 </listitem>
335 <listitem>
336 <para>
337 DFT_REPO_DIR=&lt;dirname&gt;
338 </para>
339 <para>This directory is added to the white list of allowed
340 directories. This variable can hold multiple directory
341 names but is usually set equal to <literal>GIT_BASE_DIR</literal>.
342 </para>
343 </listitem>
344 <listitem>
345 <para>
346 GIT_DAEMON_OPTS=&lt;options&gt;
347 </para>
348 <para>
349 In case special options to the <command>git daemon</command>
350 command are needed, they have to be specified in this setting.
351 One example might be to adjust the port number where daemon is
352 listening. In this case, add <literal>--port=&lt;port
353 number&gt;</literal> to this variable. For more information
354 about which options can be set, take a look at the output of
355 <command>git daemon --help</command>.
356 </para>
357 </listitem>
358 </itemizedlist>
359 </para>
360
361 <para>
362 After starting the daemon, unauthenticated users can clone exported
363 repositories by using
364 </para>
365<screen role="nodump"><userinput>git clone git://gitserver/project1.git</userinput></screen>
366
367 <para>
368 As the base directory is <filename class="directory">/srv/git</filename>
369 by default (or set to a custom value in the configuration),
370 <application>git</application> interprets the incoming path
371 (/project1.git) relative to that base directory so that the repository
372 in <filename class="directory">/srv/git/project1.git</filename> is
373 served.
374 </para>
375
376 </sect3>
377
378 </sect2>
379
380</sect1>
Note: See TracBrowser for help on using the repository browser.