【學習記錄】CentOS建立Git服務器
阿新 • • 發佈:2017-09-04
font cat 添加 gen bsp microsoft 一行 highlight 登錄
0.所有代碼沒有特別說明都是在root權限下執行,其他用戶權限執行失敗時候,切換root用戶或者添加sudo前綴。
1.安裝git,並創建git用戶
yum install git
adduser git
2.建立git倉庫
mkdir /data/gitrepo
3.給用戶git添加gitrepo的讀寫權限
chown -R git:git /data/gitrepo
4.使用git建立空項目
git init -bare /data/gitrepo/projectname.git
5.將/etc/ssh/sshd_config中將RSA認證打開,取消下sshd_config中下列代碼的註釋
1.RSAAuthentication yes
2.PubkeyAuthentication yes
3.AuthorizedKeysFile .ssh/authorized_keys
6.賦予authorized_keys權限
cd /home/git
mkdir .ssh
chmod 700 .ssh
touch .ssh/authorized_keys
chmod 600 .ssh/authorized_keys
cd /home
chown -R git:git git
7.上傳ssh key
在客戶端創建ssh key
ssh-keygen -t rsa -C "your_email"
將生成的公鑰文件id_rsa.pub內容復制到.ssh/authorized_keys中。
有多個公鑰的時候,將公鑰都復制到.ssh/authorized_keys中,一行一個公鑰。
8.禁用git用戶的shell登錄
在/etc/passwd中修改git使用的shell,如果git為最新創建的用戶,一般會在最後一行
git:x:1001:1001:,,,:/home/git:/bin/bash
修改為
git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell
9.客戶端clone
git clone [email protected]:/data/git/learngit.git
10.參考鏈接
https://segmentfault.com/a/1190000008403740
http://www.cnblogs.com/gattaca/p/6252416.html
http://blog.csdn.net/wave_1102/article/details/47779401
【學習記錄】CentOS建立Git服務器