摘要:記錄新電腦需要clone和push代碼到GitHub
error:
Cloning into 'FPGA_common'…
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
遇到的這個錯誤信息:
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
說明你嘗試使用 SSH 協議從 GitHub 克隆倉庫,但你的 SSH key 沒有被 GitHub 識別或沒有配置。解決方法如下:
? 解決步驟
1. 檢查是否已經有 SSH key
在終端輸入以下命令:
ls ~/.ssh
查看是否有 id_rsa 和 id_rsa.pub(或 id_ed25519 和 id_ed25519.pub)文件。
2. 如果沒有 SSH key,生成一個:
ssh-keygen -t ed25519 -C "your_email@example.com"
按提示一路回車即可。
3. 將公鑰添加到 GitHub:
cat ~/.ssh/id_ed25519.pub
復制輸出的內容。
然后登錄 GitHub SSH 設置頁面,點擊:
New SSH key → 填入標題 → 粘貼剛才復制的公鑰 → 保存。
4. 測試 SSH 連接
ssh -T git@github.com
如果看到如下信息表示成功:
Hi username! You've successfully authenticated...
5. 再次克隆倉庫
git clone git@github.com:username/FPGA_common.git
🔁 或者用 HTTPS 克隆(無需配置 SSH)
如果你不想配置 SSH,也可以改用 HTTPS:
git clone https://github.com/username/FPGA_common.git
這樣每次操作可能需要輸入 GitHub 用戶名和密碼,或者使用 Personal Access Token 替代密碼。
如果你想我幫你一步步檢查你現在的 SSH 狀態,只需要告訴我你執行了哪一步。