git秘鑰問題解析及gitlab配置
1、背景描述
前端開發(fā)從進項目,代碼有幾周沒提交了,公司管理員給分配了gitlab的權(quán)限,就幫他弄下,結(jié)果一直報以下錯誤:
Please make sure you have the correct access rights and the repository exists.
git clone [email protected]:ruanjianlaowang/web.git c:\Users\軟件老王\Desktop\web --progress Host key verification failed. fatal: Could not read from remote repository.
從報錯信息看,要么遠程倉庫地址不對,要么是沒有權(quán)限,重新生成秘鑰了和檢查地址了好多次,就是不行,弄的有點懷疑人生了,最后突然發(fā)現(xiàn)問題所在,記錄下,希望能幫到朋友們。
2、解決方案
2.1 首先下載下git客戶端
地址:
https://git-scm.com/download/win

下載后exe文件,直接next、next到最后一步,全部默認安裝就好了。
2.2 生成ssh秘鑰
(1)##?生成ssh密鑰
ssh-keygen?-t?rsa?-C?<your?email>
例如:ssh-keygen -t rsa -C [email protected]
(2)#?一路回車保存為默認名字
Enter?file?in?which?to?save?the?key?(/home/raunjianlaowang/.ssh/id_rsa):
Enter?passphrase?(empty?for?no?passphrase):
Enter?same?passphrase?again:
(3)##?會自動生成兩個文件
私鑰文件:id_rsa 公鑰文件:id_rsa.pub
#?windows
C:\Users\登陸用戶名稱\.ssh
例如老王的:
C:\Users\Administrator\.ssh
linux
/home/ruanjianlaowang/.ssh
2.3 打開公鑰文件id_rsa.pub

以ssh-rsa 開頭,直接全部復制粘貼:

2.4 復制到gitlab賬戶中的
登陸賬戶右上角的設(shè)置->ssh秘鑰->復制公鑰到空白框中添加即可。

2.5 其他
項目主要是在idea中使用的,以下這一步剛開始我們沒做,不過在找問題的有朋友提到可能是這個問題,也隨便做了做,不過以前記得是沒有這樣做的。
#?檢查項目/全局?git配置
git?config?--global?--list
#?修改git賬號為遠程倉庫賬號密碼
git?config?--global?user.name?<your?name>
git?config?--global?user.email?<your?email>
2.6 還是說重點吧,錯誤怎么解決的
為什么很簡答的操作,反復確認了還是報:Please make sure you have the correct access rights and the repository exists呢?
Enter?file?in?which?to?save?the?key?(/home/raunjianlaowang/.ssh/id_rsa):
Enter?passphrase?(empty?for?no?passphrase):
Enter?same?passphrase?again:
問題出在了這一步了,Enter passphrase,這里輸入了賬戶密碼,導致在idea中一直報沒有權(quán)限,但是idea卻沒有提示要錄入密碼,后面通過git命令拉取的時候,彈出讓輸入密碼,輸入居然好了,才發(fā)現(xiàn)這里要直接回車,不能輸入密碼,否則idea中就無法拉取遠程倉庫的代碼。
Enter passphrase要直接回車,不能錄入密碼!
Enter passphrase要直接回車,不能錄入密碼!
Enter passphrase要直接回車,不能錄入密碼!
更多信息請關(guān)注公眾號:「軟件老王」,關(guān)注不迷路,軟件老王和他的IT朋友們,分享一些他們的技術(shù)見解和生活故事。
