前言:之前学习了如何使用 git 后,一直想搭建一个本机搭建一个 git server 的,一开始不知道走了弯路用了 gitosis,折腾了我好几天都没配置好。昨晚查资料发现 gitosis 早就过时了,更新很慢取而代之的是 gitolite。后来在查看 gitosis 和 gitolite 的时候发现了这篇文章,其实如果对权限要求不高的话,都不需要安装 gitosis, gitolite,gitlab 之类的管理软件,所以今天一大早起来就开始研究了,最终成功了。 一、创建一个 Standard 新用户名为 git。 $ sudo chmod u+w /etc/sudoers # 找到这一行 "root ALL=(ALL) ALL",在下面添加 "AccountName ALL=(ALL) ALL" (这里是 git ALL=(ALL) ALL)并保存。 二、client 端,设置为下图 三、验证一下是否能连接上 git 用户 $ ssh git@yourComputerName.local 四、使用 ssh rsa 公钥 1) 如果 client 端已经创建 ssh rsa 公钥, 则执行 2),否则先创建: $ cd ~ 2) 把 ssh rsa 公钥拷贝到 server 端 (id_rsa.pub 文件在创建的时候,是可以改名的。这里也可以先把 ~/.ssh/id_rsa.pub 拷贝到别的地方并重新命名 $ cp ~/.ssh/id_rsa.pub /tmp/yourName.pub) $ ssh git@yourComputerName.local mkdir .ssh # 登陆 server 并创建 .ssh 文件夹 3) 修改 server 端的 sshd_config $ ssh git@yourComputerName.local $ cd /etc $ sudo chmod 666 sshd_config $ vi sshd_config #PermitRootLogin yes 改为 PermitRootLogin no # exit 经过上面几步已经配置好了,下面来测试一下了: 1) 在 server 端创建空的 repository $ cd path/to 2) 在 client 端,创建 local repository 并 push $ cd path/to $ mkdir newrepo $ cd newrepo $ git init $ touch README $ git add . $ git commit -m "initial commit" $ git remote add origin git@yourComputerName:/path/to/newrepo.git # 如果直接之前在 server 端创建的 newrepo.git 是在 home 目录,则这里地址为:git@yourComputerName:newrepo.git $ git push origin master
|
|