over 6 years ago
OS:CentOS 6.8
yum -y update
yum -y install git
// 新增 git 專用群組
groupadd gitgroup
// 新增 git 帳號並加入到 git 群組
adduser git -g gitgroup
// 建立 git 專案資料夾
mkdir -p /git/projects
// 變更擁有者跟權限
chgrp gitgroup /git/projects
chmod 2770 /git/projects
// 使用 git 帳號
su git
// 建立新專案資料夾
mkdir -p /git/projects/worldhappy
// 檢查一下 owner 要是 gitgroup
ls -ld /git/projects/worldhappy
// 初始化 git ,所有新增檔案目錄權限均為使用者本身與群組可讀寫,其它人員則無權限
git init --shared=0660 --bare /git/projects/worldhappy
// 檢查一下權限
ls -l /git/projects/worldhappy
// 新增用戶並指定加入 gitgroup
useradd -g gitgroup sam
// 設定使用者專案連結
ln -s /git/projects ~sam/projects
// 建立&配置用戶 SSH Key
mkdir -p ~sam/.ssh
ssh-keygen -t rsa -f ~sam/.ssh/sam_git -N ''
cat ~sam/.ssh/sam_git.pub >> ~sam/.ssh/authorized_keys
chown -Rf sam:gitgroup ~sam/.ssh
chmod 600 ~sam/.ssh/authorized_keys
// 移除公鑰
rm ~sam/.ssh/sam_git.pub
// 私鑰抓出來給使用者
mv ~sam/.ssh/sam_git ~sam/
使用者使用下面的路徑操作 git
sam@192.168.200.211:projects/worldhappy