寫(xiě)在前面
??本文主要介紹通過(guò)SSH的方式拉取GitLab代碼。
一、場(chǎng)景描述
??之前筆者是通過(guò) HTTP + Personal access token 的方式拉取、更新、提交代碼的。直到有一天,休了個(gè)假?;貋?lái)之后,發(fā)現(xiàn)代碼無(wú)法拉取,其他同事也遇到同樣問(wèn)題。
報(bào)如下錯(cuò)誤:
$ git pull
error: RPC failed; HTTP 500 curl 22 The requested URL returned error: 500
fatal: the remote end hung up unexpectedly
查詢(xún)資料,未果。
不知道是不是GitLab服務(wù)器端有人做了什么sao操作,還是其他什么原因。網(wǎng)上查詢(xún)了一些資料,有說(shuō)是緩存問(wèn)題,經(jīng)親測(cè),也沒(méi)什么卵用。
// 配置緩存的方式
git config --global http.postBuffer 157286400
https://stackoverflow.com/questions/44780221/git-push-failing-http-500-curl-22-the-requested-url-returned-error-500-internal
后來(lái),經(jīng)測(cè)試,發(fā)現(xiàn)通過(guò)SSH的方式可以正常拉取代碼。
如有人發(fā)現(xiàn)HTTP 500 具體錯(cuò)誤原因的,請(qǐng)?jiān)u論區(qū)指出,感謝~
二、具體步驟
1.環(huán)境說(shuō)明
名稱(chēng) | 說(shuō)明 |
---|---|
Windows版本 | Win10/X64 |
IntelliJ IDEA | 2019.2 |
2.生成秘鑰
進(jìn)入用戶(hù)當(dāng)前目錄, 注意.ssh是隱藏目錄
admin@LAPTOP-ROP3B248 MINGW64 ~
$ cd ~/.ssh
輸入命令,user@email.com 換成自己郵箱即可,其他的直接默認(rèn)回車(chē)即可。
admin@LAPTOP-ROP3B248 MINGW64 ~/.ssh
$ ssh-keygen -t rsa -b 4096 -C "user@email.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/admin/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/admin/.ssh/id_rsa
Your public key has been saved in /c/Users/admin/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:5P4vWucgzRdv9adk2VJmp+Bt/7S2Q9AMU4KEzmHrBN0 user@email.com
The key's randomart image is:
+---[RSA 4096]----+
| . +..... |
| . = E o. |
| * o = |
| o = . o |
| S o . *|
| . + . = Xo|
| o = + % =|
| +.= = Bo|
| ...oo oo*|
+----[SHA256]-----+
// 會(huì)生成2個(gè)文件
admin@LAPTOP-ROP3B248 MINGW64 ~/.ssh
$ ll
total 8
-rw-r--r-- 1 admin 197121 3389 Nov 13 11:08 id_rsa
-rw-r--r-- 1 admin 197121 747 Nov 13 11:08 id_rsa.pub
3.GitLab添加秘鑰
登錄GitLab,頭像那個(gè)位置,點(diǎn)擊settings。選擇左側(cè)SSH Keys
復(fù)制生成的文件 id_rsa.pub(公鑰) 文件的內(nèi)容,粘貼到key中,點(diǎn)擊Add key
此時(shí),郵箱會(huì)收到郵件。
4.驗(yàn)證SSH方式
將 {git地址} 替換為自己的git地址即可
admin@LAPTOP-ROP3B248 MINGW64 ~/.ssh
$ ssh -T git@{git地址}
The authenticity of host '{git地址}' can't be established.
ED25519 key fingerprint is SHA256:gyiXoXNV3lz8RqbCXnmVBBPW7WxuBVoOxnNbq8TSsUo.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '{git地址}' (ED25519) to the list of known hosts.
Welcome to GitLab, User!
4.更改原有HTTP方式為SSH
更改拉取代碼的方式,以IDEA為例,選中項(xiàng)目,右鍵,Git-》Repository-》Remotes
修改URL由HTTP修改為SSH方式。說(shuō)明:IDEA版本不同,步驟會(huì)有所不同
原有: http://{git地址}/ace-group/ace-conf-parent.git
修改為: git@{git地址}:ace-group/ace-conf-parent.git
至此,就又可以愉快地玩耍了~
三、參考資料
gitlab 配置ssh key,通用ssh拉取代碼
寫(xiě)在后面
??如果本文內(nèi)容對(duì)您有價(jià)值或者有啟發(fā)的話,歡迎點(diǎn)贊、關(guān)注、評(píng)論和轉(zhuǎn)發(fā)。您的反饋和陪伴將促進(jìn)我們共同進(jìn)步和成長(zhǎng)。文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-775937.html
系列文章
【GitLab】-HTTP Basic: Access denied.remote:You must use a personal access token
【GitLab】-批量克隆更新GibLab項(xiàng)目腳本(Python版本)文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-775937.html
到了這里,關(guān)于【GitLab】-HTTP 500 curl 22 The requested URL returned error: 500~SSH解決的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!