0.所有代码没有特别说明都是在root权限下执行,其他用户权限执行失败时候,切换root用户或者添加sudo前缀。

 

1.安装git,并创建git用户

yum install git
adduser git  

 

2.建立git仓库

mkdir /data/gitrepo

 

3.给用户git添加gitrepo的读写权限

chown -R git:git /data/gitrepo

 

4.使用git建立空项目

git init --bare /data/gitrepo/projectname.git

 

5.将/etc/ssh/sshd_config中将RSA认证打开,取消下sshd_config中下列代码的注释

1.RSAAuthentication yes     
2.PubkeyAuthentication yes     
3.AuthorizedKeysFile  .ssh/authorized_keys

 

6.赋予authorized_keys权限

cd /home/git
mkdir .ssh
chmod 700 .ssh
touch .ssh/authorized_keys
chmod 600 .ssh/authorized_keys
cd /home
chown -R git:git git

 

7.上传ssh key

在客户端创建ssh key

ssh-keygen -t rsa -C "your_email"

 将生成的公钥文件id_rsa.pub内容复制到.ssh/authorized_keys中。

有多个公钥的时候,将公钥都复制到.ssh/authorized_keys中,一行一个公钥。

 

8.禁用git用户的shell登录

在/etc/passwd中修改git使用的shell,如果git为最新创建的用户,一般会在最后一行

git:x:1001:1001:,,,:/home/git:/bin/bash  

 修改为

git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell  

 

9.客户端clone

 git clone git@192.168.8.34:/data/git/learngit.git

 

 

10.参考链接

https://segmentfault.com/a/1190000008403740

http://www.cnblogs.com/gattaca/p/6252416.html

http://blog.csdn.net/wave_1102/article/details/47779401

posted on 2017-09-04 00:06  独步倾城  阅读(96)  评论(0编辑  收藏  举报