摘要:记录新电脑需要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 状态,只需要告诉我你执行了哪一步。