安裝git,并創(chuàng)建git用戶
[root@muluo ~]# yum install -y git // 安裝 git
[root@muluo ~]# adduser git // 創(chuàng)建 git 用戶
[root@muluo ~]# passwd git // 為 git 用戶 設置密碼
初始化一個倉庫
選擇一個目錄 來作為你的 git 倉庫地址
[root@muluo ~]# cd mnt
[root@muluo mnt]# mkdir gittest
[root@muluo mnt]# cd gittest
[root@muluo gittest]# mkdir mygitrepo.git
[root@muluo gittest]# cd mygitrepo.git
初始化倉庫
[root@muluo mygitrepo.git]# git init --bare
//Initialized empty Git repository in /mnt/gittest/mygitrepo.git/
修改權限
[root@muluo mygitrepo.git]# chown -R git:git /mnt/gittest/mygitrepo.git
倉庫已經創(chuàng)建完成。
這個時候可以在本地克隆一下試一試:
提示輸入密碼采记,這時只需要輸入git用戶的密碼就行了。
當然每次輸入密碼很煩揉抵,所以接下來我們配置sshkey
配置ssh key
在本地C:\Users\win7.ssh生成ssh
ssh-keygen -t rsa -C "your_email@example.com"
之后一直按enter就會生成兩個文件。將pub打開復制下來 導入到 centos 秘狞。
[root@muluo mygitrepo.git]# cd /home/git
[root@muluo git]# mkdir .ssh
[root@muluo git]# cd.ssh
[root@muluo .ssh]# touch authorized_keys
將本地的pub復制進這個authorized_keys文件里 ,緊接著 回到上級目錄 修改權限
[root@muluo git]# chown -R git:git .ssh
修改 .ssh權限為700 蹈集,.ssh/authorized_keys 文件的權限為 600
[root@muluo git]# chmod 700 .ssh
[root@muluo git]# chmod 600 .ssh/authorized_keys
再次在本地克滤甘浴:
git 服務器 搭建成功!!!