Create a git server "go" on Linux

Source: Internet
Author: User
Tags unpack using git

Transferred from: http://blog.csdn.net/xiongmc/article/details/9176785

If you have fewer people using git, you can use the following steps to quickly deploy a GIT server environment.

1. The client generates an SSH public key for server-side identification.

Every engineer who needs to use a GIT server needs to generate an SSH public key

Go to your ~/.ssh directory to see if you have a file name and filename. pub to name a pair of files, this file name is usually ID_DSA or Id_rsa. The. pub file is the public key, and the other file is the key. If you do not have these files (or simply not even the. SSH directory), you can use the Ssh-keygen program to build them, the program is provided by the SSH package in the LINUX/MAC system, and is included in the Msysgit package on Windows:

123456789
$ ssh-keygen generating public/private RSA key pair. Enter file in which to save the key (/USERS/SCHACON/.SSH/ID_RSA): Enter passphrase (empty for no passphrase): Enter same p Assphrase again:your identification has been saved In/users/schacon/.ssh/id_rsa. Your public key have been saved in/users/schacon/.ssh/id_rsa.pub.the key fingerprint is:43:c5:5b:5f:b1:f1:50:43:ad:20:a6 : 92:6a:1f:9a:3a [email protected]

It asks you to confirm where to save the public key (. Ssh/id_rsa), then it will let you repeat a password two times, if you do not want to enter the password when using the public key, you can leave blank.

Now, all users who have done this will have to give their public key to either you or the Git Server Manager (assuming the SSH service is set to use the public key mechanism). They only need to copy the contents of the. pub file and then e-email it. The public key looks roughly like this:

1234567
$ cat ~/.ssh/id_rsa.pub Ssh-rsa aaaab3nzac1yc2eaaaabiwaaaqeakloupkdhrfhy17sbrmtipnltgk9tjom/bwdsugpl+ nafzlhdtyw7hdi4yz5ew18jh4jw9jbhufrviqzm7xlelevf4h9lfx5qvkbpppswg0cda3pbv7kodj/mtyblwxfcr+ hao3fxritbqxix1nkhxphazsmcilq8v6rjsnaqwdsdmfvslvk/7xat3faojoasncm1q9x5+3v0ww68/ eifmb1zuufljqjkprrx88xypndvjynby6vw/pb0rwert/enmz+aw4ozpntpi89zpmvmluayrd2ce86z/il8b+gw3r3+ 1nkatmikjn2so1d01qratlmqvssbxnrrfi9wrf+m7q== [email protected]
2. Erecting the server

First, create a ' git ' user and create an. SSH directory for it, under the user's home directory:

1234
$ sudo adduser git$ su git$ cd$ mkdir. SSH
Note: Adding a git user to the Sudo group in order to resolve the Ubuntu system under "About ' xx ' users not in the sudoers file, this matter will be reported. "Solution. What do you do? Execute the following command under the user with sudo: [email protected]:~$ sudo vim/etc/sudoers Then, add git all= (all:all) All #
# This file must is edited with the ' Visudo ' command as root.
#
# Consider adding local content in/etc/sudoers.d/instead of
# directly modifying this file.
#
# See the Mans page for details on how to write a sudoers file.
#
Defaults Env_reset
Defaults secure_path= "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# Host alias Specification
# User alias Specification
# CMND alias Specification
# User Privilege Specification
Root all= (All:all) all
# members of the admin group may gain root privileges
%admin all= (All) all
# Allow members of the group sudo to execute any command
%sudo all= (All:all) all
git all= (all:all) all
# See Sudoers (5) For more information on "#include" directives:
#includedir/ETC/SUDOERS.D

Next, add the developer's SSH public key to the user's Authorized_keys file. Suppose you received several public keys by e-mail to coexist in the temporary file (

or [email protected]:~$ sudo cat/home/client2/.ssh/id_rsa.pub >>/home/git/.ssh/authorized_keys). Just add them to the Authorized_keys file.

123
$ cat/tmp/id_rsa.john.pub >> ~/.ssh/authorized_keys$ cat/tmp/id_rsa.josie.pub >> ~/.ssh/authorized_keys$ Cat/tmp/id_rsa.jessica.pub >> ~/.ssh/authorized_keys

You can now run git init with the –bare option to set an empty repository, which initializes a repository that does not contain a working directory.

1234
$ cd/opt/git$ mkdir project.git$ cd project.git$ git--bare init

At this point, the developer can add it as a remote repository, push a branch, and upload the first version of the project to the repository. It is important to note that each time you add a new project, you need to log in to the host through the shell and create a pure repository. We might as well use gitserver as the hostname of the GIT user and repository. If you are running the host on the network and you set gitserver in DNS to point to that host, the following commands are available:

1234567
# on an engineer's computer $ cd myproject$ git init$ git Add. $ git commit-m ' initial commit ' $ git remote add origin [email protected]:/ opt/git/project.git$ git push Origin master

In this way, the cloning and pushing of other people are just as simple:

1234
$ git clone [email protected]:/opt/git/project.git$ vim readme$ git commit-am ' fix for the README file ' $ Git push origin Master

This method can be very fast for a few developers to set up a read-write Git service.

As an extra precaution, you can use Git's git-shell simple tool to limit the activity of git users to git-only. By setting it as the shell that the git user is logged into, the user cannot have normal shell access to the host. To achieve this, it is necessary to indicate that the user's login shell is Git-shell, not bash or CSH. You may have to edit the/etc/passwd file

1
$ sudo vim/etc/passwd

At the end of the file, you should be able to find a line like this:

1
Git:x:1000:1000::/home/git:/bin/sh

Change the bin/sh to/usr/bin/git-shell (or view its location with which Git-shell). The line is modified to look like this:

1
Git:x:1000:1000::/home/git:/usr/bin/git-shell

Now git users can only use SSH connections to push and get the Git repository, rather than using the host shell directly. If you try to log in, you will see a rejection message like this:

123
$ SSH [email protected]fatal:what do think I am? A Shell? (What do you think I am?) Shell, huh? ) Connection to Gitserver closed. (The Gitserver connection is disconnected.) )

Q&a Reference

(4) In order to integrate into SCM, we install git on Linxu
Http://www.examw.com/linux/all/182529/index-2.html
Create a git server on Linux
http://lionest.iteye.com/blog/1447310
http://blog.csdn.net/andy_android/article/details/6996134
Receiving objects:26% (5668/21560), 8.06 MiB | 183 kib/s 21560)
(5)
Q:
[email protected]:~/myproject.git$ git push origin master Ssh:connect to host Xiongmc-desktop Port 22:connection refused
Fatal:the remote end hung up unexpectedly
[email protected]:~/myproject.git$ git push Origin master
Ssh:connect to host Xiongmc-desktop Port 22:connection refused
Fatal:the remote end hung up unexpectedly

A:
http://blog.csdn.net/zlm_250/article/details/7979221
sudo apt-get install Openssh-server
sudo net start sshd
sudo ufw disable
SSH localhost

(6)
Q:
Under Ubuntu system "about ' xx ' users are not in the sudoers file, this matter will be reported. "The workaround


A:
Http://blog.sina.com.cn/s/blog_bede36550101b0av.html
Git all= (all:all) all


(7)
Q:
[email protected]:~/myproject.git$ git push Origin master
[email protected] ' s password:
Fatal: '/opt/git/project.git ' does not appear to be a git repository
Fatal:the remote end hung up unexpectedly


A:
http://www.dotkam.com/2010/08/22/gitolite-does-not-appear-to-be-a-git-repository/








2013-5-26
(1)
Q:
[email protected]:~/myproject2$ git push Origin master
Agent admitted failure to sign using the key.
[email protected] ' s password:
ERROR:SRC Refspec Master does not match any.
Error:failed to push some refs to ' [email protected]:/opt/git/project.git/'


A:
Http://www.linuxidc.com/Linux/2013-03/81022.htm


If the initial code warehouse is empty, Git push Origin master commits the code with the following exception:


(2)
Q:
[email protected]:~/myproject2$ git push Origin master
Agent admitted failure to sign using the key.
[email protected] ' s password:
Permission denied, please try again.
[email protected] ' s password:
Counting Objects:3, done.
Writing objects:100% (3/3), 213 bytes, done.
Total 3 (delta 0), reused 0 (Delta 0)
Error:insufficient permission for adding a object to repository database./objects


Fatal:failed to write Object
Error:unpack failed:unpack-objects Abnormal exit
to [email protected]:/opt/git/project.git/
! [Remote rejected] master, Master (N/A (unpacker error))
Error:failed to push some refs to ' [email protected]:/opt/git/project.git/'
A:
The server has no permissions.
http://linsheng1990526.blog.163.com/blog/static/203824150201231423917228/


(3)
Http://www.linuxidc.com/Linux/2013-03/81022.htm
Q:


[email protected]:~/myproject2$ git push Origin master
Agent admitted failure to sign using the key.
[email protected] ' s password:
Counting Objects:3, done.
Writing objects:100% (3/3), 213 bytes, done.
Total 3 (delta 0), reused 0 (Delta 0)
remote:error:refusing to update checked out Branch:refs/heads/master
Remote:error:By default, updating the current branch in a Non-bare repository
Remote:error:is denied, because it'll make the index and work tree inconsistent
Remote:error:with What do you pushed, and would require ' git reset--hard ' to match
Remote:error:the work tree to HEAD.
Remote:error:
Remote:error:You can set ' receive.denycurrentbranch ' configuration variable to
Remote:error: ' Ignore ' or ' warn ' in the remote repository to allow pushing into
Remote:error:its Current Branch; However, this isn't recommended unless you
Remote:error:arranged to update their work tree to match the what's pushed in some
Remote:error:other.
Remote:error:
Remote:error:To squelch This message and still keep the default behaviour, set
Remote:error: ' receive.denycurrentbranch ' configuration variable to ' refuse '.
to [email protected]:/opt/git/project.git/
! [Remote rejected] master, master (branch is currently checked out)
Error:failed to push some refs to ' [email protected]:/opt/git/project.git/'


A:


$cd. Git
$vim Config


The original contents of the configuration file are:


[Core]
repositoryformatversion = 0
FileMode = True
Bare = False
Logallrefupdates = True


Include the following in the configuration file:


[Receive]
Denycurrentbranch = Ignore


(4)
Linux server: Ubuntu config git service-yat Yun Gull


Http://www.xue5.com/Server/Linux/667461.html

Create a git server "go" on Linux

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.