分享

在 mac os 上搭建 git server

 方海龙的书馆 2015-11-19

前言:之前学习了如何使用 git 后,一直想搭建一个本机搭建一个 git server 的,一开始不知道走了弯路用了 gitosis,折腾了我好几天都没配置好。昨晚查资料发现 gitosis 早就过时了,更新很慢取而代之的是 gitolite。后来在查看 gitosis 和 gitolite 的时候发现了这篇文章,其实如果对权限要求不高的话,都不需要安装 gitosis, gitolite,gitlab 之类的管理软件,所以今天一大早起来就开始研究了,最终成功了。

参考文章1, 参考文章2

一、创建一个 Standard 新用户名为 git。

$ sudo chmod u+w /etc/sudoers
$ sudo vi /etc/sudoers
# 找到这一行 "root ALL=(ALL) ALL",在下面添加 "AccountName ALL=(ALL) ALL" (这里是 git ALL=(ALL) ALL)并保存。

二、client 端,设置为下图

三、验证一下是否能连接上 git 用户

$ ssh git@yourComputerName.local

# Are you sure you want to continue connecting (yes/no)? yes
# Password:
# Last login: Fri Jan  3 09:00:55 2014
# exit

四、使用 ssh rsa 公钥

  1) 如果 client 端已经创建 ssh rsa 公钥, 则执行 2),否则先创建:

$ cd ~
$ ssh-keygen -t rsa  # 默认存放路径 ~/.ssh/id_rsa.pub

  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 文件夹
$ scp ~/.ssh/id_rsa.pub git@yourComputerName.local:.ssh/authorized_keys

# id_rsa.pub                                    100%  405     0.4KB/s   00:00  

  3) 修改 server 端的 sshd_config

复制代码
$ ssh git@yourComputerName.local
$ cd /etc
$ sudo chmod 666 sshd_config
$ vi sshd_config
#PermitRootLogin yes     改为 PermitRootLogin no

# 下面几项把前面的 #注释 去掉
#RSAAuthentication yes
#PubkeyAuthentication yes
#AuthorizedKeysFile .ssh/authorized_keys
#PasswordAuthentication no
#PermitEmptyPasswords no

#UsePAM yes          改为
UsePAM no
# exit
复制代码

  经过上面几步已经配置好了,下面来测试一下了:  

    1) 在 server 端创建空的 repository

$ cd path/to
$ mkdir newrepo.git $ cd newrepo.git $ git init --bare
# --bare flag 只是用来存储 pushes,不会当做本地 repository 来使用的。

    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
复制代码

 

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多