Windows上使用Cygwin和Gitolite搭建Git伺服器
阿新 • • 發佈:2019-01-07
安裝Cygwin
- 開啟setup.exe, 選擇Install from Internet
- 選擇安裝Cygwin到C:\cygwin
- 選擇儲存下載檔案的目錄為C:\
- 選擇下載站點的映象
-
選擇安裝以下軟體包:
- Net | openssh (不要選成openssl)
- Devel | git
- Devel | git-completion
- Devel | git-gui
- Devel | git-svn (如果需要同時提交到svn)
- Devel | gitk
- Editors | vim
整合Cygwin和Windows Security
- 開啟C:\cygwin\Cygwin.bat
-
$ bin/cyglsa-config
Are you sure you want to continue? (yes/no) - 選擇yes
- 重啟Windows
搭建SSH伺服器
- 開啟C:\cygwin\Cygwin.bat
-
$ ssh-host-config
*** Info: Generating /etc/ssh_host_key
*** Info: Generating /etc/ssh_host_rsa_key
*** Info: Generating /etc/ssh_host_dsa_key
*** Info: Generating /etc/ssh_host_ecdsa_key
*** Info: Creating default /etc/ssh_config file
*** Info: Creating default /etc/sshd_config file
*** Info: Privilege separation is set to yes by default since OpenSSH 3.3.
*** Info: However, this requires a non-privileged account called 'sshd'.
*** Info: For more info on privilege separation read /usr/share/doc/openssh/README.privsep.
*** Query: Should privilege separation be used? (yes/no) -
選擇yes
*** Info: Note that creating a new user requires that the current account have
*** Info: Administrator privileges. Should this script attempt to create a
*** Query: new local account 'sshd'? (yes/no) -
選擇yes
*** Info: Updating /etc/sshd_config file
*** Info: Added ssh to C:\WINDOWS\system32\driversc\services
*** Warning: The following functions require administrator privileges!
*** Query: Do you want to install sshd as a service?
*** Query: (Say "no" if it is already installed as a service) (yes/no) - 選擇yes *** Query: Enter the value of CYGWIN for the daemon: []
-
輸入tty
*** Info: The sshd service has been installed under the LocalSystem
*** Info: account (also known as SYSTEM). To start the service now, call
*** Info: `net start sshd' or `cygrunsrv -S sshd'. Otherwise, it
*** Info: will start automatically after the next reboot.
*** Info: Host configuration finished. Have fun! - 配置結束,確認埠22可用。啟動服務:sc start sshd
允許SSH客戶端訪問
- 建立一個名為git的使用者,設定密碼,並確保密碼不會過期。
- 在Cygwin Bash中,執行命令: mkpasswd -l -u git >> /etc/passwd
驗證下SSH登入
- 開啟Cygwin Bash
-
$ ssh [email protected]
[email protected] ~
$ ssh [email protected]
The authenticity of host '10.0.2.15 (10.0.2.15)' can't be established.
ECDSA key fingerprint is 5d:a6:81:98:43:fa:5a:f6:df:ba:18:b9:a0:76:87:f8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.2.15' (ECDSA) to the list of known hosts.
[email protected]'s password:
Could not chdir to home directory /home/git: No such file or directory
Copying skeleton files.
These files are for the users to personalise their cygwin experience.
They will never be overwritten nor automatically updated.
`./.bashrc' -> `/home/git//.bashrc'
`./.bash_profile' -> `/home/git//.bash_profile'
`./.inputrc' -> `/home/git//.inputrc'
`./.profile' -> `/home/git//.profile'
[email protected] ~
$ - 以git使用者登入成功
建立SSH金鑰, 並使能夠通過SSH identity以git使用者登入SSH伺服器
- 開啟Cygwin Bash
-
$ ssh-keygen -t rsa (所有輸入都為空,即使用預設配置,密碼為空)
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/Administrator/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/Administrator/.ssh/id_rsa.
Your public key has been saved in /home/Administrator/.ssh/id_rsa.pub.
The key fingerprint is:
6a:02:9f:42:99:7c:fe:52:e7:a9:fe:1b:15:1e:70:31 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
| . E. |
| o . |
| o |
| . o . o |
| * . S o |
| . = ..... |
| . =.oo.. |
| ..+ o. |
| o+oo. |
+-----------------+ -
$ ssh-copy-id [email protected] (輸入git使用者密碼)
$ ssh-copy-id [email protected]
[email protected]'s password:
Now try logging into the machine, with "ssh '[email protected]'", and check in:
~/.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting. -
驗證下,以git使用者登入:ssh [email protected]
$ ssh [email protected]
Last login: Sat Jun 11 23:06:14 2011 from china-fe1bdcde5
[email protected] ~
$ - 不需要輸入密碼,即登入成功
- 開啟Cygwin Bash
- $ cd /tmp
- $ git clone git://github.com/sitaramc/gitolite.git
- $ cd gitolite/src/
- $ ./gl-easy-install git 10.0.2.15 alec (可以單獨執行gl-easy-install檢視各個引數的意義)
- 根據安裝嚮導一步步完成配置(其中需要配置alec的密碼,生成SSH金鑰)
-
當走到需要編輯配置檔案(用vim編輯)的時候,在開頭插入:$ENV{PATH} = "/usr/local/bin:/bin:/usr/bin";,儲存並退出(:wq) 如:
# configuration variables for gitolite
$ENV{PATH} = "/usr/local/bin:/bin:/usr/bin";
# PLEASE READ THE DOCUMENTATION BEFORE EDITING OR ASKING QUESTIONS
# ( http://github.com/sitaramc/gitolite/blob/pu/doc/gitolite.rc.mkd )
# ( or http://sitaramc.github.com/gitolite/doc/gitolite.rc.html )
# this file is in perl syntax. However, you do NOT need to know perl to edit
# it; it should be fairly self-explanatory and easy to maintain - 繼續完成安裝。當完成安裝之後,可以在當前使用者的home目錄下面看到gitolite-admin目錄。
- $ cd ~/gitolite-admin
-
$ git status
[email protected] ~/gitolite-admin
$ git status
# On branch master
nothing to commit (working directory clean)
到此整個git server已經安裝結束,可以參考Gitolite文件來配置:新增user和repository