天天看點

在LINUX上建立GIT伺服器【轉】

如果使用git的人數較少,可以使用下面的步驟快速部署一個git伺服器環境。

每個需要使用git伺服器的工程師,自己需要生成一個ssh公鑰

進入自己的~/.ssh目錄,看有沒有用 檔案名 和 檔案名.pub 來命名的一對檔案,這個 檔案名 通常是 id_dsa 或者 id_rsa。 .pub 檔案是公鑰,另一個檔案是密鑰。假如沒有這些檔案(或者幹脆連 .ssh 目錄都沒有),你可以用 ssh-keygen 的程式來建立它們,該程式在 Linux/Mac 系統由 SSH 包提供, 在 Windows 上則包含在 MSysGit 包裡:

它先要求你确認儲存公鑰的位置(.ssh/id_rsa),然後它會讓你重複一個密碼兩次,如果不想在使用公鑰的時候輸入密碼,可以留白。

現在,所有做過這一步的使用者都得把它們的公鑰給你或者 Git 伺服器的管理者(假設 SSH 服務被設定為使用公鑰機制)。他們隻需要複制 .pub 檔案的内容然後 e-email 之。公鑰的樣子大緻如下:

首先,建立一個 ‘git’ 使用者并為其建立一個 .ssh 目錄,在使用者主目錄下:

注意:将git使用者添加到sudo組,以便解決

ubuntu系統下“關于'xx'使用者不在 sudoers檔案中,此事将被報告。”的解決方法。

怎麼做?在具有sudo使用者下執行如下指令:

xiongmc@xiongmc-desktop:~$ sudo vim /etc/sudoers

然後,添加 git     ALL=(ALL:ALL) ALL  

#

# This file MUST be edited with the 'visudo' command as root.

# Please consider adding local content in /etc/sudoers.d/ instead of

# directly modifying this file.

# See the man 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 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                        

接下來,把開發者的 SSH 公鑰添加到這個使用者的 authorized_keys 檔案中。假設你通過 e-mail 收到了幾個公鑰并存到了臨時檔案裡(

現在可以使用 –bare 選項運作 git init 來設定一個空倉庫,這會初始化一個不包含工作目錄的倉庫。

這時,開發人員就可以把它加為遠端倉庫,推送一個分支,進而把第一個版本的工程上傳到倉庫裡了。值得注意的是,每次添加一個新項目都需要通過 shell 登入主機并建立一個純倉庫。我們不妨以 gitserver 作為 git 使用者和倉庫所在的主機名。如果你在網絡内部運作該主機,并且在 DNS 中設定 gitserver 指向該主機,那麼以下這些指令都是可用的:

這樣,其他人的克隆和推送也一樣變得很簡單:

用這個方法可以很快捷的為少數幾個開發者架設一個可讀寫的 Git 服務。

作為一個額外的防範措施,你可以用 Git 自帶的 git-shell 簡單工具來把 git 使用者的活動限制在僅與 Git 相關。把它設為 git 使用者登入的 shell,那麼該使用者就不能擁有主機正常的 shell 通路權。為了實作這一點,需要指明使用者的登入shell 是 git-shell ,而不是 bash 或者 csh。你可能得編輯 /etc/passwd 檔案

在檔案末尾,你應該能找到類似這樣的行:

把 bin/sh 改為 /usr/bin/git-shell (或者用 which git-shell 檢視它的位置)。該行修改後的樣子如下:

現在 git 使用者隻能用 SSH 連接配接來推送和擷取 Git 倉庫,而不能直接使用主機 shell。嘗試登入的話,你會看到下面這樣的拒絕資訊:

(4)為了內建到SCM,我們在Linxu上安裝GIT

http://www.examw.com/linux/all/182529/index-2.html

在LINUX上建立GIT伺服器

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:

xiongmc@xiongmc-desktop:~/myproject.git$ git push origin master ssh: connect to host xiongmc-desktop port 22: Connection refused

fatal: The remote end hung up unexpectedly

xiongmc@xiongmc-desktop:~/myproject.git$ git push origin master 

ssh: connect to host xiongmc-desktop port 22: Connection refused

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)

ubuntu系統下“關于'xx'使用者不在 sudoers檔案中,此事将被報告。”的解決方法

http://blog.sina.com.cn/s/blog_bede36550101b0av.html

git ALL=(ALL:ALL) ALL

(7)

git@xiongmc-desktop's password: 

fatal: '/opt/git/project.git' does not appear to be a git repository

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

2013-5-26

(1)

xiongmc@xiongmc-desktop:~/myproject2$ git push origin master

Agent admitted failure to sign using the key.

git@localhost's password: 

error: src refspec master does not match any.

error: failed to push some refs to 'git@localhost:/opt/git/project.git/'

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

如果初始的代碼倉庫為空,git push origin master送出代碼的時候會出現以下異常:

(2)

Permission denied, please try again.

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 an object to repository database ./objects

fatal: failed to write object

error: unpack failed: unpack-objects abnormal exit

To git@localhost:/opt/git/project.git/

 ! [remote rejected] master -> master (n/a (unpacker error))

伺服器無權限。

http://linsheng1990526.blog.163.com/blog/static/203824150201231423917228/

(3)

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 will make the index and work tree inconsistent

remote: error: with what you pushed, and will 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 is not recommended unless you

remote: error: arranged to update its work tree to match what you pushed in some

remote: error: other way.

remote: error: To squelch this message and still keep the default behaviour, set

remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.

 ! [remote rejected] master -> master (branch is currently checked out)

$cd .git

$vim config

該配置檔案的原始内容為:

[core]

        repositoryformatversion = 0

        filemode = true

        bare = false

        logallrefupdates = true

在該配置檔案中加入以下内容:

[receive]

denyCurrentBranch = ignore

(4)

Linux伺服器:Ubuntu配置git服務 - 逸雲沙鷗

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

【新浪微網誌】 張昺華--sky

【twitter】 @sky2030_

【facebook】 張昺華 zhangbinghua

本文版權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接配接,否則保留追究法律責任的權利.