原文地址:https://blog.csdn.net/helloworld_dream/article/details/80903315
1、安裝Git
$ yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel
$ yum install git
接下來我們 創建一個git用戶組和用戶,用來運行git服務:
$ groupadd git
$ useradd git -g git
2、創建證書登錄
收集所有需要登錄的用戶的公鑰,公鑰位於id_rsa.pub(生成方法參考第5節)文件中,把我們的公鑰導入到/home/git/.ssh/authorized_keys文件裏,一行一個。
如果沒有該文件創建它:
$ cd /home/git/
$ mkdir .ssh
$ chmod 755 .ssh
$ touch .ssh/authorized_keys
$ chmod 644 .ssh/authorized_keys
3、初始化Git倉庫
首先我們選定一個目錄作爲Git倉庫,假定是/home/gitrepo/runoob.git,在/home/gitrepo目錄下輸入命令:
$ cd /home
$ mkdir gitrepo
$ chown git:git gitrepo/
$ cd gitrepo
$ git init --bare runoob.git
Initialized empty Git repository in /home/gitrepo/runoob.git/
以上命令Git創建一個空倉庫,服務器上的Git倉庫通常都以.git結尾。然後,把倉庫所屬用戶改爲git:
$ chown -R git:git runoob.git
4、克隆倉庫
$ git clone [email protected]:/home/gitrepo/runoob.git
Cloning into 'runoob'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.
192.168.45.4 爲 Git 所在服務器 ip ,你需要將其修改爲你自己的 Git 服務 ip。
這樣我們的 Git 服務器安裝就完成。
5、本地生成ssh key
設置Git的user name和email:
$ git config --global user.name "xuhaiyan"
$ git config --global user.email "[email protected]"
執行 ssh-keygen -t rsa ,按下三次回車,可發現.ssh下生成了key