服务器端Git版本:version 1.9.4
客户端Git版本: Git bash
yum install git
sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel
cd /usr/local/src
sudo tar -zvxf git-1.9.4.tar.gz
cd git-1.9.4
sudo make prefix=/usr/local/git all
sudo make prefix=/usr/local/git install
sudo ln -s /usr/local/git/bin/* /usr/bin/
sudo yum install python python-setuptools
cd /usr/local/src
git clone git://github.com/res0nat0r/gitosis.git
cd gitosis
python setup.py install
#显示Finished processing dependencies for gitosis==0.2即表示成功
#在/root/git下新建一个名为project的Git仓库
git init --bare project.git
#打开Git Bash,输入下面命令,会出现保存ssh的文件路径等信息,可以直接回车
ssh-keygen -t rsa
stevenrao@server:~$ su - root
root@server:~$ groupadd git
root@server:~$ groupadd user
root@server:~$ useradd git -g git -m -s /bin/bash
root@server:~$ usermod -G git,user git #把git同时加入git组和user组
root@server:~$ passwd git #设置密码
root@server:~$ vim /etc/sudoers #加上下面一句 git ALL=(ALL:ALL) ALL
root@server:~$ su - git #切换到git用户下工作
git@server:~$ sudo apt-get install git git-core ssh
git@server:~$ mkdir project.git
git@server:~$ cd project.git
git@server:~/project.git$ git --bare
init Initialized empty Git repository in /home/git/project.git/
git@server:~/project.git$ cd ~
git@server:~$ sudo useradd stevenrao -g user -m -s /bin/bash
git@server:~$ sudo usermod -G git,user stevenrao #把stevenrao同时加入git组和user组
git@server:~$ sudo passwd stevenrao #设置密码
git@server:~$ mkdir /home/git/.ssh
git@server:~$ vim /home/git/.ssh/authorized_keys
sh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAp1s5dDRyMeY7q6mRlQz5DbfKC/Ebtl5/gdanOaASjnNtJPULuTyVIj3UmYzZFVaVO+3yC31+cQTGWp2bXzKEuXqIUxhygvOCr+vwfRK8FrpXOLLF5WWQYd6UgpV6/6mgRPuVVDa39zqGwKEVBgoIpiVYRBSIywbO0Qf9SGQV4CevEny8aGTZCE/UHq19ec5w9jrsvij5zt xyFlvfjIaDOb8F/b3IqZ1v5PB5UHiJaZqE0xjxFiA6wtlprkrNOQKyBI44MCjw8P964+ED+w2I4n8TisCyok5FGBn66HzdBV59166NZfP+4CFScO8hDXpUnWPvpgjhtWUQeYCMLUp5eQ== stevenrao@ubuntu
git@server:~/project.git$ vim /home/git/project.git/config
[core]
repositoryformatversion = 0 filemode = true bare = true (添加下面两行)
[receive]
denyCurrentBranch = ignore
git@server:~$ /etc/init.d/ssh restart
root@client:~$ sudo apt-get install git git-core ssh
root@client:~$ useradd stevenrao -g user -m -s /bin/bash
root@client:~$ passwd stevenrao #设置密码
root@client:~$ su -u stevenrao #切换当前用户
stevenrao@client:~$ ssh-keygen -t rsa
Generating public/private rsa key pair. Enter file in which to save the key (/home/stevenrao/.ssh/id_rsa): (直接回车)
Created directory '/home/stevenrao/.ssh'.
Enter passphrase (empty for no passphrase): (输入密码)
Enter same passphrase again: (再次确认密码)
Your identification has been saved in /home/stevenrao/.ssh/id_rsa.
Your public key has been saved in /home/stevenrao/.ssh/id_rsa.pub.
The key fingerprint is: e8:6a:dd:2d:34:57:44:a5:61:65:75:c4:89:f2:f6:e4 stevenrao@client
The key's randomart image is:
+--[ RSA 2048]----+
| .+o=+=|
| o.= .o|
| .+ |
| . .o . |
| . S .. + |
| . o . E |
| ..o + |
| ... o . |
| .. . |
+-----------------+
stevenrao@client:~$ ls -al .ssh/
total 16
drwx------ 2 stevenrao user 4096 2014-09-28 06:51 .
drwxr-xr-x 3 stevenrao user 4096 2014-09-28 06:50 ..
-rw------- 1 stevenrao user 1751 2014-09-28 06:51 id_rsa
-rw-r--r-- 1 stevenrao user 398 2014-09-28 06:51 id_rsa.pub
stevenrao@client:~$ cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAp1s5dDRyMeY7q6mRlQz5DbfKC/Ebtl5/gdanOaASjnNtJPULuTyVIj3UmYzZFVaVO+3yC31+cQTGWp2bXzKEuXqIUxhygvOCr+vwfRK8FrpXOLLF5WWQYd6UgpV6/6mgRPuVVDa39zqGwKEVBgoIpiVYRBSIywbO0Qf9SGQV4CevEny8aGTZCE/UHq19ec5w9jrsvij5ztxyFlvfjIaDOb8F/b3IqZ1v5PB5UHiJaZqE0xjxFiA6wtlprkrNOQKyBI44MCjw8P964+ED+w2I4n8TisCyok5FGBn66HzdBV59166NZfP+4CFScO8hDXpUnWPvpgjhtWUQeYCMLUp5eQ== stevenrao@client
stevenrao@client:~$ mkdir /home/stevenrao/test_proj
stevenrao@client:~$ cd /home/stevenrao/test_proj
stevenrao@client:~/test_proj$ echo "test git by stevenrao v1.0" > test.txt
stevenrao@client:~/test_proj$ git init Initialized empty Git repository in /home/stevenrao/test_proj/.git/
stevenrao@client:~/test_proj$ git add .
stevenrao@client:~/test_proj$ git commit -m 'initial commit'
stevenrao@client:~/test_proj$ git remote add origin stevenrao@172.19.44.7:/home/git/project.git
stevenrao@client:~/test_proj$ git push origin master
stevenrao@client:~/test_proj$ git push origin master
stevenrao@client:~$ git config --global user.name "stevenrao"
stevenrao@client:~$ git config --global user.email "[email protected]"
stevenrao@client:~/test_proj$ vim test.txt
test git by stevenrao v1.1
stevenrao@client:~/test_proj$ git commit -m "1.1" test.txt
stevenrao@client:~/test_proj$ git push