Gitolite是一款Perl语言开发的Git服务管理工具,通过公钥对用户进行认证,并能够通过配置文件对写操作进行基于分支和路径的精细授权。仓库地址
SSH-Config:OpenSSH SSH Client config files;SSH config是SSH客户端的一个参数配置方案,可以将一些关于SSH命令的参数放到配置文件中去,执行ssh命令的时候从文件中读取,简化命令行的操作。
应用场景:开发团队,个人客户端本地通过GIT团队协作模式,实时更新服务器信息。通过配置个人ssh-config(~/.ssh/config),结合ZSH 补全,可以实现方便、快捷的登录服务器。
效果图如下:
服务端部署gitolite: steps to install First, prepare the ssh key:
login to “git” on the server
make sure ~/.ssh/authorized_keys
is empty or non-existent
make sure your ssh public key from your workstation has been copied as $HOME/YourName.pub
Next, install gitolite by running these commands:
1 2 3 git clone https://github.com/sitaramc/gitolite mkdir -p $HOME/bin gitolite/install -to $HOME/bin
Finally, setup gitolite with yourself as the administrator:
1 gitolite setup -pk YourName.pub
If the last command doesn’t run perhaps “bin” is not in your “PATH”. You can either add it, or just run:
1 $HOME/bin/gitolite setup -pk YourName.pub
If you get any other errors please refer to the online documentation whose URL was given at the top of this file.
个人本地克隆管理库,实现维护git仓库 1 git clone git@host:gitolite-admin
新增仓库、以及日常修改权限配置文件
新增个人公钥
Example: 1 2 3 4 5 6 7 8 9 @ops_users = mike jake @dev_users = tom jerry repo cilu-h5 RW = @ops_users RW = get_host xxx R = tom R = jerry
新增仓库只需新增一个repo配置项
按需使用仓库:
1 git clone git@git2.cilugame.com:cilu-h5.git ~/ssh-config/cilu-h5/
合并本地.ssh/config脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 #!/bin/bash current_dir=$(dirname $0 ) cd ${current_dir} && export current_dirold_ssh=~/.ssh/config new_ssh=~/.ssh/config.new bak_dir=~/.ssh/backup bak_ssh="${bak_dir} /$(date +'%F_%H%M%S') " hostname=$(hostname) if [ ! -f ${old_ssh} ] ;then touch ${old_ssh} chmod 0644 ${old_ssh} fi [ -d ~/.ssh/ControlPath ] || mkdir -pv ~/.ssh/ControlPath cat<<\EOF > ${new_ssh} Host github.com Port 22 Host cnc.cilugame.com Port 11932 Host git2.cilugame.com ProxyCommand ssh -q h5@jump.cilugame.com socat - TCP:%h:%p Host * Port 932 SendEnv LANG LC_* SendEnv GIT_* ForwardAgent yes ServerAliveInterval 10 XAuthLocation /opt/X11/bin/xauth UseRoaming no ControlPersist 1h ControlMaster auto ControlPath ~/.ssh/ControlPath/%r@%h:%p Compression yes EOF if ssh -V 2>&1 | grep -q "OpenSSH_7.[2-9]" ;then echo " AddKeysToAgent yes" >> ${new_ssh} fi for file in ../*/[0-9]*do file_name=$(basename $file ) dir_name=$(dirname $file ) dir_name=$(basename $dir_name ) src_file="~/ssh-config/${dir_name} /${file_name} " echo "#========== $src_file ==========#" cat $file echo done >> ${new_ssh} system=$(uname) if [ "x$system " == "xDarwin" ] ;then old_md5=$(md5 $old_ssh | awk '{print $4}' ) new_md5=$(md5 $new_ssh | awk '{print $4}' ) else old_md5=$(md5sum $old_ssh | awk '{print $1}' ) new_md5=$(md5sum $new_ssh | awk '{print $1}' ) fi if [ "x${old_md5} " = "x${new_md5} " ] ;then rm -f $new_ssh else [ -d "$bak_dir " ] || mkdir "$bak_dir " cp $old_ssh $bak_ssh mv $new_ssh $old_ssh fi chmod 0644 ${old_ssh} if [ "$hostname " == 'oc-dev-s73' ];then sed -i 's/ControlPersist 1h/#ControlPersist 1h/g' ${old_ssh} fi
配置GIT钩子,实现自动触发,更新配置文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 cd ~/ssh-config/for dir in *do if [ -d $dir ] ;then pushd $dir > /dev/null [ -d "./.git/hooks" ] || continue echo '#!/bin/sh' > .git/hooks/post-merge echo '[ -x ./merge.sh ] && ./merge.sh' >> .git/hooks/post-merge chmod +x .git/hooks/post-merge popd > /dev/null fi done
后续有更新时(成功后会自动调用勾子进行合并操作)
1 2 cd ~/ssh-config/cilu-h5/git pull
通过使用Gitolite可以大大提高团队的协助效率,有时如果是需要提供第三方技术支持,也可以使用Gitolite进行一些简单的配置文件更新、及交付。
Last updated: 2018-09-16 15:04:42