CentOS 搭建 Git 服务器

  • 官方文档移步 Git 服务器的搭建

  • 安装 Git #yum install git

  • 创建 Git 专用用户 #useradd git,改密码 #passwd git,切换至 Git 用户 #su git,回家 $cd

  • 创建 SSH 使用的认证文件夹 $mkdir .ssh && chmod 700 .ssh,创建认证文件 $touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys

  • 添加可认证用户公钥,比如本机中 /home/seliote/.ssh/id_rsa.pub RSA 密钥文件,如果没有可以使用 ssh-keygen -t rsa -C "youremail@example.com 生成,将本机 RSA 密钥认证文件中的所有内容复制进服务器的 /home/git/.ssh/authorized_keys 中,一个信任用户的公钥一行

  • 创建一个服务器仓库目录 $mkdir project,初始化仓库目录 $cd project $git init --bare android.git(用 .git 做后缀...)

  • 退出 git 用户,并禁止 git 获取 shell,$exit,找到 git-shell 的位置 #which git-shell#vim /etc/shells,末尾添加查找到的 git-shell 的路径,#chsh git -s $(which git-shell)

  • 客户端连接,进入本机准备进行推送的测试目录 $cd project,初始化本地仓库 $git init,添加所有文件 $git add .,提交一下 $git commit -m 'initial commit',连接服务器仓库比如这样 $git remote add origin ssh://git@seliote.com:22/home/git/project/android.git,推送代码 $git push origin master

原文地址:https://www.cnblogs.com/seliote/p/10147030.html