git 服務端安裝

服務器端建立 git 用戶,用來管理 Git 服務,併爲 git 用戶設置密碼git

[root@localhost home]# id git
id: git:無此用戶
[root@localhost home]# useradd git
[root@localhost home]# passwd git

 

設置 /home/data/git/gittest.git 爲 Git 倉庫
而後把 Git 倉庫的 owner 修改成 gitshell

[root@localhost home]# mkdir -p data/git/gittest.git
[root@localhost home]# git init --bare data/git/gittest.git
Initialized empty Git repository in /home/data/git/gittest.git/
[root@localhost home]# cd data/git/
[root@localhost git]# chown -R git:git gittest.git/

  

禁用shell登陸:
出於安全考慮,第二步建立的git用戶不容許登陸shell,這能夠經過編輯/etc/passwd文件完成。找到相似下面的一行:
git:x:1001:1001:,,,:/home/git:/bin/bash
改成:
git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell緩存


git clone、push 提示輸入密碼但輸入後登陸被拒絕
客戶端建立 SSH 公鑰和私鑰
$ ssh-keygen -t rsa -C "447313241@qq.com"
由 AuthorizedKeysFile 得知公鑰的存放路徑是 .ssh/authorized_keys,其實是 $Home/.ssh/authorized_keys,因爲管理 Git 服務的用戶是 git,因此實際存放公鑰的路徑是 /home/git/.ssh/authorized_keys
在 /home/git/ 下建立目錄 .ssh安全

把專用密鑰(private and public keys)添加到 ssh-agent 的高速緩存中
ssh-add ~/.ssh/id_dsa
ssh-add -d ~/.ssh/id_xxx.pub
若是執行ssh-add時提示」Could not open a connection to your authentication agent」,能夠現執行命令:
ssh-agent bash
而後再執行上述 ssh-add 操做
而後能夠進行clone等操做了bash

push 出錯的解決 (branch is currently checked out)
是因爲git默認拒絕了push操做,須要進行設置,修改.git/config文件後面添加以下代碼:
[receive]
denyCurrentBranch = ignore服務器

相關文章
相關標籤/搜索