分类: 系统运维
2015-04-02 14:06:52
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
上面的好像错了的:
应该这样干的:[git@Mini ~]$ sudo git init --bare project.git
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 #设置密码
创建证书登录:
收集所有需要登录的用户的公钥,就是他们自己的id_rsa.pub文件,把所有公钥导入到/home/git/.ssh/authorized_keys文件里,一行一个。
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 "stevenrao@qq.com"
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