??筆者最近在新 Linux 中安裝 GitLab 后,發(fā)現(xiàn)一個詭異的事情。當配置完管理員賬號、SSH 密鑰之后、開啟防火墻端口號、在 GitLab 新建倉庫 test 等等之后,筆者嘗試在遠程客戶端 Windows 上使用 git clone 來 clone 這個在 GitLab 上的倉庫,使用的是 SSH 協(xié)議。但無論 clone 的 URL 是否正確,終端提示輸入密碼,且輸入任何密碼都不對。完整提示信息內(nèi)容如下:
筆者報錯時的運行環(huán)境:
GitLab:gitlab-ee-14.3.6-ee.0.el8.x86_64
GitLab 上的 Linux:CentOS Stream 8 x86_64
遠程客戶端 Windows:Windows 10 教育版文章來源地址http://www.zghlxwxcb.cn/news/detail-440103.html
$ git clone git@xxx.xxx.xxx.xxx:XXX/test.git
Cloning into 'test'...
/c/Users/xxx/.ssh/config line 2: Unsupported option "rsaauthentication"
git@xxx.xxx.xxx.xxx's password:
Permission denied, please try again.
git@xxx.xxx.xxx.xxx's password:
34xxxPermission denied, please try again.
git@xxx.xxx.xxx.xxx's password:
git@xxx.xxx.xxx.xxx: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
??但奇怪的是,如果使用 HTTP 協(xié)議進行 clone、push 卻沒有任何問題。筆者在反復地卸載、重裝 GitLab,試了各種方法才發(fā)現(xiàn),這個密碼其實是 GitLab 所在的 Linux 上的一個賬戶名為 git 的賬戶密碼。這個賬戶是怎么來的呢?實際上,在第一次使用命令 gitlab-ctl reconfigure
初始化 GitLab 配置時,GitLab 會自動為 Linux 創(chuàng)建五個賬戶,分別是:
-
git
-
gitlab-redis
-
gitlab-psql
-
gitlab-prometheus
-
gitlab-www
??因為這些賬戶在被創(chuàng)建時,GitLab 并沒有提示我們輸入密碼,所以我們并不知道密碼,或者它們本來就沒有密碼。不過,我們在知道賬戶名的時候就可以強制改密碼了??梢允褂萌缦旅顏砀馁~戶 git 的密碼:
??在設(shè)置完賬戶 git 的密碼后,筆者已經(jīng)一切就已經(jīng)結(jié)束了,結(jié)果后面還有一個大坑等著。在提示密碼后,輸入設(shè)置的賬戶 git 的密碼后,雖然沒有提示密碼錯誤,但 clone 時卻報了如下的錯誤:
git clone does not appear to be a git repository fatal: Could not read from remote repository.
??筆者反復檢查過,clone 時使用的 SSH 的 URL 是從 GitLab 項目中復制下來的,URL 沒有問題。在反復安裝不同的 Linux 與相應的 GitLab 后,這才發(fā)現(xiàn)原因。筆者前面安裝 GitLab 使用的 Linux 操作系統(tǒng)是 CentOS Stream 8,但截止至筆者編寫本博客時,GitLab 并未對 CentOS Stream 提供 GitLab 安裝包,于是筆者想當然地以 CentOS 8 安裝包來代替,所以在安裝后的 GitLab 的 SSH 環(huán)境不正確,以至于引發(fā)了各種問題。
??當筆者使用 CentOS 8 安裝 GitLab 后,在沒有主動設(shè)置賬戶 git 的密碼時,使用 SSH 協(xié)議進行 clone、push 時,不僅連輸入密碼這個過程都免了,也沒有產(chǎn)生任何報錯。
成功運行時的環(huán)境:
GitLab:gitlab-ee-14.3.6-ee.0.el8.x86_64
GitLab 上的 Linux:CentOS 8 x86_64文章來源:http://www.zghlxwxcb.cn/news/detail-440103.html
遠程客戶端 Windows:Windows 10 教育版
到了這里,關(guān)于解決GitLab中使用SSH的git clone總是提示輸入密碼且任何密碼都不對的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!