搭建git服务器

install git server on centos 7

yum install git

adduser git

<!-- 建立账户 -->
# adduser git
<!-- 打开配置文件 -->
# vi /etc/passwd

原始值 修改后值

git:x:1000:1000::/home/git:/bin/bash git:x:1000:1000::/home/git:/usr/bin/git-shell

开启 SSH RSA 验证

<!-- 打开配置文件 -->
# vi /etc/ssh/sshd_config


原始值 修改后值
#RSAAuthentication yes RSAAuthentication yes
#PubkeyAuthentication yes PubkeyAuthentication yes

修改连接超时时间

原始值 

#ClientAliveInterval 0 
#ClientAliveCountMax 3 

修改后值

ClientAliveInterval 0 #修改保持连接时间,
ClientAliveCountMax 3 #修改保持连接次数。

设置ssh超时断连
vim /etc/profile
在HOSTNAME
HISTIZE
后追加timeout超时时间
MOUT=600;600表示超过300秒无操作即断开连接。

并确保 “AuthorizedKeysFile” 的值为 “.ssh/authorized_keys”。重启 SSH 服务。

# systemctl restart sshd.service
<!-- 进入目录 -->
# cd /home/git
<!-- 创建 Git 仓库 [name] 为仓库名 -->
# git init --bare [name].git
<!-- 创建目录 -->
# mkdir .ssh
<!-- 进入目录 -->
# cd .ssh
<!-- 创建文件 -->
# touch authorized_keys

<!-- 指定为 Git 账户 -->
# chown -R git.git [name].git
# chown -R git.git /home/git/.ssh/

客户端

<!-- 拷贝仓库 [server ip] 为服务端 IP -->
# git clone git@[server ip]:/home/git/[name].git
 

references

https://www.jianshu.com/p/2f3093791d91

http://www.cnblogs.com/jerehedu/p/4626095.html

转载请注明出处, 更多博文请访问https://www.cnblogs.com/guoapeng/
原文地址:https://www.cnblogs.com/guoapeng/p/4626144.html