Git For Windows官網(wǎng) http://code.google.com/p/msysgit/
tortoisegit官網(wǎng) http://code.google.com/p/tortoisegit/
copssh用于windows下創(chuàng)建SSH服務器 https://www.itefix.no/i2/copssh
Putty http://www.putty.org/
Gitolite官方網(wǎng)址:http://github.com/sitaramc/gitolite
Gitolite在線文檔:http://sitaramc.github.com/gitolite/
Git官網(wǎng) http://git-scm.com/
gitweb官網(wǎng) https://git.wiki.kernel.org/index.php/Gitweb
學習TortoiseGit教程用這個TortoiseGit日常使用指南.pdf
Git教程用這個 Git中文教程.pdf
sudo apt-get install highlight vim #安裝vim并高亮語法,安裝Gitolite的時候要用到。如果已安裝了此部可省掉。
ubuntu默認并沒有安裝ssh服務,如果通過ssh鏈接ubuntu,需要自己手動安裝ssh-server。判斷是否安裝ssh服務,可以通過如下命令進行:
ssh localhost
安裝命令:
sudo apt-get install openssh-server
系統(tǒng)將自動進行安裝,安裝完成以后,先啟動服務:
sudo /etc/init.d/ssh start
啟動后,可以通過如下命令查看服務是否正確啟動
ps -e|grep ssh
重啟sshd的命令
/etc/rc.d/sshd restart
1、使用本地機器生成密鑰(這里使用Git Bash)
#產(chǎn)生 id_rsa, id_rsa.pub
ssh-keygen -t rsa –C “kanghui@mtc.com.cn”
楓@FREEBIRD ~ $ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key(/c/Users/楓/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in/c/Users/楓/.ssh/id_rsa.
Your public key has been saved in /c/Users/楓/.ssh/id_rsa.pub.
The key fingerprint is:
22:d4:67:ef:65:ba:8e:07:f7:d1:f9:0a:b1:79:4f:8c楓@FREEBIRD
2、復制生成的id_rsa.pub公鑰文件到遠程服務器上
# 將 id_rsa.pub 丟到 Server 上, 大家的 publickey 都需要傳到 Server 上.
scp ~/.ssh/id_rsa.pub roan@192.168.35.10:/home/roan/.ssh/authorized_keys
再復制一份到服務器的/temp文件夾下面一會gitolite要用。
scp ~/.ssh/id_rsa.pub roan@192.168.35.10:/tmp/MTC.pub#注意MTC.pub在gitolite里面就是你的用戶名
還有一個命令簡體了命令操作(ssh-copy-id),和上面的操作是一樣的。
ssh-copy-id 把本地主機的公鑰復制到遠程主機的authorized_keys文件上。
ssh-copy-id 也會給遠程主機的用戶主目錄(home)和~/.ssh, 和~/.ssh/authorized_keys設置合適的權(quán)限 。
ssh-copy-id-i ~/.ssh/id_rsa.pub roan@192.168.35.10
[注: ssh-copy-id 把密鑰追加到遠程主機的.ssh/authorized_key 上.]
3、將私鑰id_rsa生成Putty格式
putty作為遠程客戶端在putty不能識別直接從服務器拷貝來的私鑰,需要使用puttygen.exe進行格式轉(zhuǎn)換
(1)、打開puttygen.exe--> Conversions --> Import Key
(2)、選擇拷貝過來的私鑰文件id_rsa
(3)、Save privatekey->id_rsa.ppk(保存私鑰)
4、打開putty.exe
1)、Session --> HostName (填寫服務器地址或者域名)
2)、Connection -->SSH --> Auth (點Browse選擇剛生成的id_rsa.ppk)
3)、open
成功打開后出現(xiàn)如下提示:
login as: root
Authenticating with public key"imported-openssh-key"
----------------------------------------------------------------------------------
當然你有可能會遇到這個錯誤 [因為我遇到了,呵呵]:
Permissions 0755 for '你配置的公鑰文件路徑'are too open.
這個是因為這幾個文件權(quán)限設置的有點問題
執(zhí)行命令: chmod 600 /root/.ssh/authorized_keys
想要控管 User / Project 權(quán)限, 而且還想要控管 branch / tag 等讀寫權(quán)限, 則需要靠 Gitolite 等套件來協(xié)助.
gitolite - SSH-basedgatekeeper for git repositories
系統(tǒng): Ubuntu Linux
Server: 192.168.35.10
Project name:project_name
Gitosis (Git)Repository 位置: /home/git/repositories
Group name: git
sudo apt-get install gitolite git-core
roan@ubuntu:~$ sudo adduser --system --shell /bin/bash --gecos'git version control' --group --disabled-password --home /home/git git
[sudo] password for roan:
正在添加系統(tǒng)用戶"git" (UID 116)...
正在添加新組"git" (GID 125)...
正在將新用戶"git" (UID 116)添加到組"git"...
創(chuàng)建主目錄"/home/git"...
1. ssh roan@192.168.35.10 # 登錄到Git Server
2. sudo su – git #切換到git賬號
3. gl-setup /tmp/MTC.pub # 加入管理者的 Public key(公鑰). 注意: 此檔名即是賬號名稱, 不要使用 id_rsa.pub 當檔名, 建議用 "賬號.pub" 當檔名
命令過程如下 #按大寫ZZ兩次退出Vim-tiny #按q!可以退出vim按wq保存并退出vim
git@ubuntu:~$ gl-setup /tmp/MTC.pub
The default settings in the rcfile (/home/git/.gitolite.rc) are fine for most
people but if you wish to makeany changes, you can do so now.
hit enter...
Select an editor. To change later, run 'select-editor'.
1. /bin/ed
2. /bin/nano <---- easiest
3. /usr/bin/vim.basic
4. /usr/bin/vim.tiny
Choose 1-4 [2]: 3
此時要特別注意如果要用Gitweb的話一定要
把$REPO_UMASK =0077; 改成 $REPO_UMASK = 0027; # gets you 'rwxr-x---'。
creating gitolite-admin...
Initialized empty Gitrepository in /home/git/repositories/gitolite-admin.git/
creating testing...
Initialized empty Gitrepository in /home/git/repositories/testing.git/
[master (root-commit) f489c2a]start
2 files changed, 6 insertions(+)
create mode 100644 conf/gitolite.conf
create mode 100644 keydir/mtc.pub
4. exit
1. Gitolite 的專案權(quán)限 / 賬號管理是使用 Git 來管理, 專案名稱: gitolite-admin.git
2. git clone git@192.168.35.10:gitolite-admin # 因為 Gitolite 是用 gitolite-admin.git 來管理, 所以需要抓下來修改、設定(未來所有管理也是如此)
3. cdgitolite-admin # 會看到下述
conf/gitolite.conf# 設定檔, 設定誰可以讀寫哪個專案的 Repository
keydir # 目錄, 放每個賬號的 public key. 放置的檔案命名: user1.pub, user2.pub(user1, user2.. 為賬號名稱(檔名 = 賬號), 建議使用 "賬號.pub" 當檔名)
1. cdgitolite-admin
2. vimconf/gitolite.conf #
會看到下述,
不要動他, 于最下方設定自己的 Group /
專案名稱即可.
repo gitolite-admin
RW+ = admin
repo testing
RW+ = @all
3. 由此檔案新增 / 修改后, commit + push 即可.
1. git clonegitolite@example.com:testing #
對應 gitolite.conf
的 repo testing,
會出現(xiàn)下述訊息
Cloning intotesting...
warning: You appear to have cloned an empty repository.
2. cd testing
3. touch readme
4. git add .
5. git commit -m'add readme'
6. git push originmaster
1. cd gitolite-admin
2. cp/tmp/user1.pub keydir/user1.pub # 請依照實際賬號命名, 不要取 user1, user2
3. cp/tmp/user1.pub keydir/user1@machine.pub # 若相同賬號, 則使用 user@machine.pub
4. cp/tmp/user2.pub keydir/user2.pub
5. git addkeydir/user1.pub keydir/user1@machine.pub keydir/user2.pub
6. git commit -m'add user1, user1@machine, user2 public key'
7. git push
下述摘錄自: Gitolite 構(gòu)建 Git 服務器 - 授權(quán)使用者建立屬于自己的空間 (User 下面可以建 N 個 Repository), 在此就不記載, 請自行詳見: 此文的章節(jié) 2.4.3
#取自 2.3.1 授權(quán)文件基本語法
@admin = jiangxin wangsheng
repogitolite-admin
RW+ = jiangxin
repoossxp/.+
C = @admin
RW = @all
repotesting
RW+ = @admin
RW master = junio
RW+ pu = junio
RW cogito$ = pasky
RW bw/ = linus
- = somebody
RW tmp/ = @all
RW refs/tags/v[0-9] = junio
#取自 2.3.3 ACL
repo testing
RW+ = jiangxin @admin
RW = @dev @test
R = @all
repo 語法: <權(quán)限> [零個或多個正規(guī)表示式批配的引用] = <user> [<user>...]
每條指令必須指定一個權(quán)限, 權(quán)限可以用下面任何一個權(quán)限的關(guān)鍵字: C, R, RW, RW+, RWC, RW+C, RWD, RW+D, RWCD,RW+CD
C : 建立
R : 讀取
RW : 讀取 + 寫入
RW+ : 讀取 + 寫入 + 對 rewind 的 commit 做強制 Push
RWC : 授權(quán)指令定義 regex (regex 定義的 branch、tag 等), 才可以使用此授權(quán)指令.
RW+C : 同上, C 是允許建立和 regex 配對的引用 (branch、tag 等)
RWD : 授權(quán)指令中定義 regex (regex 定義的 branch、tag 等), 才可以使用此授權(quán)指令.
RW+D : 同上, D 是允許刪除和 regex 配對的引用 (branch、tag 等)
RWCD : 授權(quán)指令中定義 regex (regex 定義的 branch、tag 等), 才可以使用此授權(quán)指令.
RW+CD : C 是允許建立和 regex 配對的引用 (branch、tag 等), D 是允許刪除和 regex 配對的引用 (branch、tag 等)
- : 此設定為不能寫入, 但是可以讀取
注: 若 regex 不是以 refs/ 開頭, 會自動于前面加上 refs/heads/
@all 代表所有人的意思
@myteam user1user2 : user1, user2 都是屬于 myteam 這個群組
下述全部都在 gitolite-admin.git 內(nèi)操作
新增賬號
cp/tmp/user1.pub keydir/user1.pub # 注意: 檔名要取 "賬號.pub"
新增專案
1. vimconf/gitolite.conf #
增加 repo,
例如:
repo testing
RW @all
2. git clone gitolite@example.com:testing
設定專案
vimconf/gitolite.conf # 增加 repo, 設定讀寫群組、使用者的權(quán)限
1. cd ~/
2. mkdir DVBT-TEST
3. cd DVBT-TEST
4. git init
5. git remote add origin git@192.168.35.10:DVBT-TEST.git
# gitosis 會自行于/srv/gitosis/repositories 新增
6. touch readme
7. git add .
8. git commit -m'initial'
9. git push originmaster:refs/heads/master # 或 git push origin master
$ ssh git@192.168.35.10
hello mtc, this is gitolite 2.3-1 (Debian) running ongit 1.7.10.4
the gitolite config gives you the followingaccess:
R W DVBT-TEST
R W gitolite-admin
@R_ @W_ testing
Connection to 192.168.35.10 closed.
Gitweb是用來在網(wǎng)頁上查看GIT代碼庫的。沒有Gitweb,我們?nèi)匀豢梢允褂肎it客戶端從Gitolite服務器上獲取代碼。Gitweb演示:http://git.kernel.org/
安裝GitWeb
第一步: 安裝gitweb和highlight,Gitweb安裝在/usr/share/gitweb #這里就是你看到的網(wǎng)頁地方的代碼
$ sudo apt-get installhighlight gitweb #自動會安裝apache2
第二步:修改gitweb.conf
$ sudo vim /etc/gitweb.conf
#change $projectroot to /home/git/repositories
#change $projects_list to /home/git/projects.list
# AddHighlighting at the end #在網(wǎng)頁中查看代碼的時候可以高亮語法
$feature{'highlight'}{'default'}= [1];
第三步:修改git倉庫文件夾的權(quán)限
Changegitolite instance to allow access for gitweb. First append www-data to gitgroup so gitweb can access the repos, then change the permissions for git reposand the projects list, finally restart apache:
sudo usermod -a -G git www-data
sudo chmod g+r/home/git/projects.list
sudo chmod -R g+rx /home/git/repositories
sudo service apache2 restart或者sudo /etc/init.d/apache2 restart #效查一樣都是重啟apache
第四步:Finallyyou need to tell gitolite which repo you want to show up in gitweb. To do thisedit the gitolite.conf file from the gitolite-admin.git repo:
repotesting
RW+ = @all
R = gitweb
the best solution I found for this was to edit the .gitolite.rc file andto change the umask.
1. the default umask for repositories is0077; change this if you run stuff
2. like gitweb and find it can't read therepos. Please note the syntax; the
3. leading 0 is required
#$REPO_UMASK = 0077; # gets you 'rwx------'
#$REPO_UMASK = 0027; # gets you 'rwxr-x---'
$REPO_UMASK = 0022; # gets you 'rwxr-xr-x'
# useradd start
$feature{'highlight'}{'default'}= [1];
$feature{'highlight'}{'override'}= 1;
$feature{'blame'}{'default'}= [1];
$feature{'blame'}{'override'}= 1;
$feature{'pickaxe'}{'default'}= [1];
$feature{'pickaxe'}{'override'}= 1;
$feature{'search'}{'default'}= [1];
$feature{'search'}{'override'}= 1;
$feature{'grep'}{'default'}= [1];
$feature{'grep'}{'override'}= 1;
$feature{'snapshot'}{'default'}= ['tgz', 'tbz2', 'zip'];
$feature{'snapshot'}{'override'}= 1;
$feature{'avatar'}{'default'}= ['gravatar'];
$feature{'avatar'}{'override'}= 1;
#$fallback_encoding= 'utf-8';
$fallback_encoding= 'EUC-CN';
#$projects_list_description_width = 50;
$site_name= "MTC git Server";
# Title
$home_link_str= 'MTC Projects';
https://github.com/kogakure/gitweb-theme