Linux uses Gitolite to build Git servers (servers and clients can be the same machine)

Source: Internet
Author: User
Tags commit mkdir ssh ssh access git clone

In general, configure a git server, you need a server, but also need a client to verify the success of the server, and the general developers have only a basic server, it needs this server as a git server, and as a client to use, The following tutorial is an example of a server and a client being the same server. If the server and the client are required to separate, only the server-side and client operations listed below can be operated on the appropriate machine.

First step (server side): Create Git server private account
Name of the account is git, set up password for it after creation

The code is as follows Copy Code
# useradd-m-s/bin/bash git
# passwd git
Enter New UNIX Password:
Retype new UNIX Password:
Passwd:password updated successfully

Switch to git user, create the installation directory bin under the home directory/home/git

The code is as follows Copy Code
root@letuknowit:~# Su-git
git@letuknowit:~$ MkDir Bin
git@letuknowit:~$ LL
Total 24
Drwxr-xr-x 3 git git 4096 Aug 20 10:38./
Drwxr-xr-x 8 root 4096 Aug 20 10:36. /
-rw-r--r--1 git git 3. bash_logout
-rw-r--r--1 git git 3486 Apr 3 BASHRC
Drwxrwxr-x 2 git git 4096 Aug 10:38 bin/
-rw-r--r--1 git git 675 Apr 3

Get gitolite and install, gitolite to install on the server side, to ensure that Git is installed on the system before installation

The code is as follows Copy Code
git@letuknowit:~$ git clone git://github.com/sitaramc/gitolite


Cloning into ' gitolite ' ...


Remote:counting objects:8682, done.


Remote:total 8682 (Delta 0), reused 0 (Delta 0)


Receiving objects:100% (8682/8682), 3.61 MiB | KIB/S, done.


Resolving deltas:100% (4917/4917), done.


git@letuknowit:~$ LL


Total 28


Drwxr-xr-x 4 git git 4096 Aug 20 10:40./


Drwxr-xr-x 8 root 4096 Aug 20 10:36. /


-rw-r--r--1 git git 3. bash_logout


-rw-r--r--1 git git 3486 Apr 3 BASHRC


Drwxrwxr-x 2 git git 4096 Aug 10:38 bin/


Drwxr-xr-x 6 git git 4096 Aug 10:40 gitolite/


-rw-r--r--1 git git 675 Apr 3


git@letuknowit:~$ Gitolite/install-ln


git@letuknowit:~$ LL


Total 28


Drwxr-xr-x 4 git git 4096 Aug 20 10:40./


Drwxr-xr-x 8 root 4096 Aug 20 10:36. /


-rw-r--r--1 git git 3. bash_logout


-rw-r--r--1 git git 3486 Apr 3 BASHRC


Drwxrwxr-x 2 git git 4096 Aug 10:44 bin/


Drwxr-xr-x 6 git git 4096 Aug 10:40 gitolite/


-rw-r--r--1 git git 675 Apr 3


Step Two (client): Create the Gitolite server administrator user and create an administrator user key
Because we are on the same server, the direct exit back to the root user, then become the client mode, if the client and server separately, do not need to exit instructions, directly in the client to execute the instructions to add users. Here's Gitolite server administrator username we're called gitadmin.

The code is as follows Copy Code
git@letuknowit:~$ exit
Logout
root@letuknowit:~# useradd-m-s/bin/bash Gitadmin
root@letuknowit:~# passwd Gitadmin
Enter New UNIX Password:
Retype new UNIX Password:
Passwd:password updated successfully

Switch to Gitadmin user, create user key

The code is as follows Copy Code
root@letuknowit:~# Su-gitadmin


gitadmin@letuknowit:~$ mkdir. SSH


gitadmin@letuknowit:~$ LL


Total 24


Drwxr-xr-x 3 gitadmin gitadmin 4096 Aug 20 10:48./


Drwxr-xr-x 9 root 4096 Aug 20 10:46. /


-rw-r--r--1 gitadmin gitadmin Apr 3. Bash_logout


-rw-r--r--1 gitadmin gitadmin 3486 APR 3 BASHRC


-rw-r--r--1 gitadmin gitadmin 675 APR 3


Drwxrwxr-x 2 gitadmin Aug gitadmin 4096 10:48. ssh/


gitadmin@letuknowit:~$ ssh-keygen-f. ssh/gitadmin


Generating public/private RSA key pair.


Enter passphrase (empty for no passphrase):


Enter same Passphrase again:


Your identification has been saved in. ssh/gitadmin.


Your public key has been saved in. ssh/gitadmin.pub.


The key fingerprint is:


84:a0:9d:d6:c6:43:57:0e:22:cd:67:97:8e:03:be:09 Gitadmin@letuknowit


The key ' s Randomart image is:


+--[RSA 2048]----+


| Ooo o ... |


| o b++ooo |


| .      +.*+.+. |


| . E..      Oo. |


| .       OS. |


| o |


| |


| |


| |


+-----------------+


Next, copy the Administrator public key (Gitadmin.pub) to the home directory of the GIT user on the server, because we have the server and the client together, so it is convenient, if it is two machines, you may have to think of some way to copy the file.

The code is as follows Copy Code
gitadmin@letuknowit:~$ exit
Logout
root@letuknowit:~# cp/home/gitadmin/.ssh/gitadmin.pub/home/git/
root@letuknowit:~# Ll/home/git
Total 36
Drwxr-xr-x 4 git git 4096 Aug 20 10:53./
Drwxr-xr-x 9 root 4096 Aug 20 10:46. /
-RW-------1 git git 788 Aug 10:45. bash_history
-rw-r--r--1 git git 3. bash_logout
-rw-r--r--1 git git 3486 Apr 3 BASHRC
Drwxrwxr-x 2 git git 4096 Aug 10:44 bin/
-rw-r--r--1 root root 412 Aug 10:53 gitadmin.pub
Drwxr-xr-x 6 git git 4096 Aug 10:40 gitolite/
-rw-r--r--1 git git 675 Apr 3

Step three (server side): Configure the Gitolite server
Back to the server side, configure the Gitolite server with the Gitolite Administrator user's public key (Gitadmin.pub) replicated from the client:

The code is as follows Copy Code
root@letuknowit:~# Su-git


git@letuknowit:~$ Gitolite SETUP-PK gitadmin.pub


Initialized empty Git repository in/home/git/repositories/gitolite-admin.git/


Initialized empty Git repository in/home/git/repositories/testing.git/


WARNING:/home/git/.ssh missing; Creating a new One


(This is normal on a brand new install)


WARNING:/home/git/.ssh/authorized_keys missing; Creating a new One


(This is normal on a brand new install)


git@letuknowit:~$ LL


Total 60


Drwxr-xr-x 7 git git 4096 Aug 20 10:57./


Drwxr-xr-x 9 root 4096 Aug 20 10:46. /


-RW-------1 git git 788 Aug 10:45. bash_history


-rw-r--r--1 git git 3. bash_logout


-rw-r--r--1 git git 3486 Apr 3 BASHRC


Drwxrwxr-x 2 git git 4096 Aug 10:44 bin/


-rw-r--r--1 root root 412 Aug 10:53 gitadmin.pub


Drwxr-xr-x 6 git git 4096 Aug 10:40 gitolite/


drwx------6 git git 4096 Aug 10:57. gitolite/


-RW-------1 git git 6662 Aug 10:57. gitolite.rc


-rw-r--r--1 git git 675 Apr 3


-RW-------1 git Aug 10:57 projects.list


drwx------4 git git 4096 Aug 10:57 repositories/


drwx------2 git git 4096 Aug 10:57. ssh/


You'll see a lot more folders in the home directory of Git users, depending on the results of the LL command above.

Step Fourth (Client): Verify the alias of the Gitolite Administrator account Access server and verify that the alias was successful

The code is as follows Copy Code
git@letuknowit:~$ exit
Logout
root@letuknowit:~# Su-gitadmin
gitadmin@letuknowit:~$ LL. ssh/
Total 16
Drwxrwxr-x 2 gitadmin gitadmin 4096 Aug 20 10:49./
Drwxr-xr-x 3 gitadmin gitadmin 4096 Aug 20 10:53. /
-RW-------1 gitadmin gitadmin 1679 Aug 10:49
-rw-r--r--1 gitadmin gitadmin 412 Aug 10:49
gitadmin@letuknowit:~$ Vi. Ssh/config

Switch to the Gitadmin account, create a new config file under the. ssh folder, and enter the following

The code is as follows Copy Code
Host Git
User git
hostname xxx.xxx.xxx.xxx
Port 22
Identityfile ~/.ssh/gitadmin

Host: casually defined, used for the client identification of the connected server name;
USER:SSH Login to the server's account, is the server side of that git dedicated account user name;
Hostname: Server host name, or directly fill out the server IP address;
Port: SSH access ports for the server, default 22;
Identityfile: The authentication key used by the administrator to log on to the server;

Use the server alias to manage the warehouse gitolite-admin from the Gitolite server clone Gitolite server to verify that the alias configuration was successful:

  code is as follows copy code
gitadmin@letuknowit : ~$ git clone git:gitolite-admin
cloning into ' gitolite-admin ' ...
The authenticity of host ' xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx) ' can ' t be established. The
ECDSA key fingerprint is c1:c2:6a:7a:68:c8:e5:a6:87:f4:9b:95:d5:fd:ff:09.
Are you sure your want to continue connecting (yes/no)? Yes
Warning:permanently added ' xxx.xxx.xxx.xxx ' (ECDSA) t o The list of known hosts.
Remote:counting objects:6, done.
remote:compressing objects:100% (4/4), done.
Receiving objects:100% (6/6), 763 bytes, done.
Remote:total 6 (Delta 0), reused 0 (Delta 0)

Step Fifth (client): Create a key to an ordinary user to access the Gitolite server
The system already has a Kris account, if not, you can create a own, name casually take. Create a key by Ssh-keygen first

The code is as follows Copy Code
gitadmin@letuknowit:~$ exit


Logout


root@letuknowit:~# Su-kris


kris@letuknowit:~$ ssh-keygen-f. Ssh/kris


Generating public/private RSA key pair.


Enter passphrase (empty for no passphrase):


Enter same Passphrase again:


Your identification has been saved in. Ssh/kris.


Your public key has been saved in. ssh/kris.pub.


The key fingerprint is:


18:7c:21:e8:7b:4c:2a:d9:b2:e2:eb:db:5b:94:65:49 Kris@letuknowit


The key ' s Randomart image is:


+--[RSA 2048]----+


| .. E. |


| ......       |


|  .        o+. |


| . =+         |


| o B. S |


| + = O |


| + O |


|.            O. |


|o*oo. |


+-----------------+


kris@letuknowit:~$ LL. ssh/


Total 20


DRWX------2 Kris Kris 4096 Aug 20 11:22./


Drwxr-xr-x 9 kris Kris 4096 Aug 20 09:56. /


-rw-r--r--1 Kris Kris 442 Nov 2013


-RW-------1 Kris Kris 1679 Aug 11:22


-rw-r--r--1 kris Kris 410 Aug 11:22


Copy user public key (kris.pub) to Gitolite Administrator (Gitadmin):

  code is as follows copy code
kris@letuknowit : ~$ exit
logout              
root@letuknowit:~# cp/home/kris/.ssh/kris.pub/home/gitadmin/gitolite-admin/keydir/
root@letuknowit:~# ll!$
ll/home/gitadmin/gitolite-admin/keydir/
Total
drwxrwxr-x 2 gitadmin gitadmin 4096 Aug./
12:09 Xr-xr-x 5 gitadmin gitadmin 4096 Aug 20 11:19. /
-rw-rw-r--1 gitadmin gitadmin  412 Aug 11:19 gitadmin.pub
-rw-r--r--1 root     Roo t      410 Aug 12:09 kris.pub

Use public key (Kris.pub) to create a Git repository that he can access for user kris:

The code is as follows Copy Code

gitadmin@letuknowit:~/gitolite-admin$ git Add.
gitadmin@letuknowit:~/gitolite-admin$ git status-s
M conf/gitolite.conf
A keydir/kris.pub
gitadmin@letuknowit:~/gitolite-admin$ git commit-m "Add user Kris by Kris.git and create a repo to it"

Please tell me who you are.

Run

git config--global user.email "you@example.com"
git config--global user.name "Your name"

To set your account ' s default identity.
Omit--global to set the identity is in this repository.

Fatal:empty ident <gitadmin@letuknowit. (none) > not allowed

You need to configure the username and email first, or you will be given an error message.

The code is as follows Copy Code
gitadmin@letuknowit:~/gitolite-admin$ git config--global user.email "xxx@163.com"


gitadmin@letuknowit:~/gitolite-admin$ git config--global user.name "Kris"


gitadmin@letuknowit:~/gitolite-admin$ git commit-m "Add user Kris by Kris.git and create a repo to it"


[Master Ef0bde9] Add user Kris by Kris.git and create a repo letu for it


2 files changed, 4 insertions (+)


Create mode 100644 keydir/kris.pub


gitadmin@letuknowit:~/gitolite-admin$ git status


# on Branch Master


# Your Branch is ahead's ' Origin/master ' by 1 commit.


#


Nothing to commit (working directory clean)


gitadmin@letuknowit:~/gitolite-admin$ git push Origin master


Counting Objects:10, done.


Delta compression using up to 2 threads.


Compressing objects:100% (5/5), done.


Writing objects:100% (6/6), 840 bytes, done.


Total 6 (Delta 0), reused 0 (Delta 0)


remote:initialized Empty Git repository in/home/git/repositories/letu.git/


To Git:gitolite-admin


B19c84d.. Ef0bde9 Master-&gt; Master


Switch to the user Kris with the private key (~/.ssh/kris) to try to use the private key clone "Letu" This git library:

The code is as follows Copy Code
gitadmin@letuknowit:~/gitolite-admin$ exit
Logout
root@letuknowit:~# Su-kris
kris@letuknowit:~$ LL. ssh/
Total 20
DRWX------2 Kris Kris 4096 Aug 20 11:22./
Drwxr-xr-x 9 kris Kris 4096 Aug 20 09:56. /
-rw-r--r--1 Kris Kris 442 Nov 2013
-RW-------1 Kris Kris 1679 Aug 11:22
-rw-r--r--1 kris Kris 410 Aug 11:22
kris@letuknowit:~$ Vi. Ssh/config

For convenience, we also configure an access alias for the Kris User, and then save it after entering the following content

The code is as follows Copy Code
Host Kris
User git
hostname xxx.xxx.xxx.xxx
Port 22
Identityfile ~/.ssh/kris

Here's how to clone the Letu that was previously added to this git library.

The code is as follows Copy Code

Kris@letuknowit : ~/$ git clone kris:letu
cloning into ' letu ' ...
Warning:you appear to have cloned a empty repository.
kris@letuknowit:~$ cd letu/
kris@letuknowit:~/letu$ git status
# on branch Master
#
# Initial Commit
#
Nothing to commit (create/copy files and use "Git add" to track)
kris@letuknowit:~/letu$ echo "Hello git" & Gt Init.txt
kris@letuknowit:~/letu$ git Add.
kris@letuknowit:~/letu$ git status.
# on Branch Master
#
# Initial Commit
#
# Changes to is committed:
#   (use git rm--cached ... "to Unstage)
#
#& Nbsp;new file:   init.txt
#
kris@letuknowit:~/letu$ git commit-m "init repo"
kris@letuknowit:~/ letu$ git push origin master

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.