• 在 mac os 上搭建 git server


    前言:之前学习了如何使用 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
  • 相关阅读:
    Oracle Haip无法启动问题学习
    OGG-Veridata如何对比没有主键的表?
    除PerfDog之外,还有什么性能测试工具。
    test
    Android系统WiFi网络架构
    audit2allow 添加SELinux权限
    select、poll、epoll之间的区别总结
    属性问题展开的selinux权限介绍
    android property属性property_set()&& property_get() selinux权限问题
    关于网络&wifi基础内容
  • 原文地址:https://www.cnblogs.com/eileenleung/p/3503337.html
Copyright © 2020-2023  润新知