gitlab兩種連線方式:ssh和http配置介紹

吞吞吐吐的發表於2017-10-17

 

gitlab環境部署好後,建立project工程,在本地或遠端下載gitlab程式碼,有兩種方式:ssh和http

1)ssh方式:這是一種相對安全的方式
要求將本地的公鑰上傳到gitlab中,如下圖:

window客戶機設定ssh方式連線gitlab,請見http://www.cnblogs.com/kevingrace/p/5651402.html(文章底部有介紹)

2)http連線方式

這種方式要求project在建立的時候只能選擇“Public”公開狀態,Private和Internal私有模式下不能使用http方式進行連線。(ssh方式在三種模式下都可以)。使用http方式直接連線gitlab顯然沒有ssh連線方式安全,但是也可以做些安全設定,比如在gitlab本機的iptables裡做埠限制(如上是8081埠),新增白名單等。

 

 

===================================================
gitlab上建立的專案倉庫,要注意該倉庫下的members許可權,如果某個gitlab使用者沒有設定在該倉庫members許可權下,則使用該gitlab使用者進行git clone操作可以,但是進行git push則會失敗!報錯:remote: GitLab: You are not allowed to push code to protected branches on this project.

比如,使用gitlab的kevin使用者進行git上傳下載操作,kevin使用者預設沒有加到scanhost.git專案倉庫的member許可權下。
1)git clone是可以的
[root@test ~]# git config --global user.name "王士博"
[root@test ~]# git config --global user.email "kevin@veredholdings.com"
[root@test ~]# git clone http://gitlab.kevin-inc.com/fanglianchao/scanhost.git
[root@test ~]# cd scanhost

2)git push則不允許,沒有許可權
[root@test ~]# touch README.md
[root@test ~]# git add README.md
[root@test ~]# git commit -m "add README"
[root@test ~]# git push -u origin master
.......
remote: GitLab: You are not allowed to push code to protected branches on this project.
To http://gitlab.kevin-inc.com/fanglianchao/scanhost.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'http://gitlab.kevin-inc.com/fanglianchao/scanhost.git'

需要將kevin使用者加入到scanhost.git專案倉庫的member許可權裡,這樣就有許可權進行git push了!

相關文章