学习了一下git的配置。git确实是个非常强大的工具。跟着教程把git的工作原理及常用命令学习了一下。果然很复杂。当然我是先在msysgit上学习的。随后在ubuntu里装上,就可以使用了。很好很强大。建议初学者按照这个曲线走,当然若是有人指点就更加高效了。
一开始我不知道ssh是如何工作,在网上找了很多教程,有些讲了ssh的工作原理,我总算明白,ssh的工作原理。git教程里也有讲到。
我先安装了gitosis(现在好像过时了)用它来管理git权限确实很麻烦。一开始我不知道,就用起来了。(尽信书不如无书啊!)
Fork后项目放到了GitHub,地址是https://github.com/ossxp-com/gitosis
创建一个叫git的用户,可以像这样:
$ sudo adduser git $ su git $ cd $ mkdir .ssh
也可以这样:
useradd \ -r \ -s /bin/sh \ -c 'git version control' \ -d /home/git \ git mkdir -p /home/git chown git:git /home/git
但是在配置ssh时,遇见了一个很大的问题!无论如何我也没有办法链接到服务器。这个工作消耗了我两天的时间,我在网上找各种文档对比我的配置文件,始终没有找到问题的根源。后来我解决这个问题时,都要被雷倒了。
#AuthorizedKeysFile %h/.ssh/authorized_keys
我当时写的是:
AuthorizedKeysFile ~/.ssh/authorized_keys
总是不能登陆成功。最后把它注释掉或者把“~”换成“%h”就可以了。也许这个配置跟操作系统有关系。网上很多人提示都是第二中写法的配置。在我的机器上确实不起作用。
其他的禁用空密码,不允许"root"登陆的配置都是一样的。我列出我的配置清单供大家欣赏:
# Package generated configuration file # See the sshd_config(5) manpage for details # What ports, IPs and protocols we listen for Port 22 # Use these options to restrict which interfaces/protocols sshd will bind to #ListenAddress :: #ListenAddress 0.0.0.0 Protocol 2 # HostKeys for protocol version 2 HostKey /etc/ssh/ssh_host_rsa_key HostKey /etc/ssh/ssh_host_dsa_key HostKey /etc/ssh/ssh_host_ecdsa_key #Privilege Separation is turned on for security UsePrivilegeSeparation yes # Lifetime and size of ephemeral version 1 server key KeyRegenerationInterval 3600 ServerKeyBits 1024 # Logging SyslogFacility AUTH LogLevel INFO # Authentication: LoginGraceTime 120 PermitRootLogin no StrictModes no RSAAuthentication yes PubkeyAuthentication yes #AuthorizedKeysFile %h/.ssh/authorized_keys # Don't read the user's ~/.rhosts and ~/.shosts files IgnoreRhosts yes
能登陆了试试能不能用ssh访问,如果可以就完成了大半了。
以上操作完成后就初始化gitosis:
sudo -H -u git gitosis-init < /tmp/id_dsa.pub
再修改文件权限:
$ sudo chmod 755 /opt/git/gitosis-admin.git/hooks/post-update
在git管理员的机器上用:
git clone git@gitserver:gitosis-admin.git
如果你这一步成功了。祝贺你,你真的成功了!!
在其他机器上访问可以这样:
git@test.ubuntu:/home/git/repositories/test.git git@10.10.10.10:/home/git/repositories/test.git
有人说不可以不用绝对路径。大家酌情处理。