在使用git push資料到gitlab的時候發生 Permission denied (publickey).的問題,有沒有解法?
主要是ssh的key pair的問題,在push時我們會下這樣的指令:
結果出現以下錯誤
The authenticity of host '[gitlab.example.com]:2222 (192.168.1.1:2222)' can't be established.
ECDSA key fingerprint is SHA256:mQvEZuaCUUGLk57NrP9nTQrRubov8QyMxLySL+oT5b8.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[gitlab.example.com]:2222, 192.168.1.1:2222' (ECDSA) to the list of known hosts.
git@gitlab.example.com: Permission denied (publickey).
fatal: Could not read from remote repository
原本我以為是ssh key不match,所以把 ~/.ssh/known_hosts 中的key清掉重連還是會出現一樣的錯誤。
解決
執行以下指令產生公私鑰
以下指令會產生兩個檔案在家目錄中:
$ ls
id_rsa <== 私鑰
id_rsa.pub <== 公鑰
known_hosts
接下來把公鑰id_rsa.pub 上傳到gitlab,即可順利push。