首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >为什么PyCharm push时报错了,明明已经添加SSH密钥到GitHub?一文讲清楚

为什么PyCharm push时报错了,明明已经添加SSH密钥到GitHub?一文讲清楚

作者头像
烟雨平生
发布2026-04-14 18:28:49
发布2026-04-14 18:28:49
330
举报

先讲原因:pull Github仓库时用了HTTPS。需要是SSH。

把本地仓库远程地址改为 SSH 地址,再重新push就可以了。

来看下具体情况。

在IDEA中改好代码,push时报错了:

PyCharm cosole也有报错:

代码语言:javascript
复制
fatal: could not read Username for 'https://github.com': Device not configured
Remote "origin" does not support the Git LFS locking API. Consider disabling it with:
  $ git config lfs.https://github.com/helloworldtang/GPT_teacher-3.37M-cn.git/info/lfs.locksverify false
Git credentials for https://github.com/helloworldtang/GPT_teacher-3.37M-cn.git not found:
credential fill errors:
exit status 1
error: failed to push some refs to 'https://github.com/helloworldtang/GPT_teacher-3.37M-cn.git'

错哪了?没有配置用户名密码?

之前已经在Github上配置过SSH密钥了。

再来GitHub → Settings → SSH and GPG keys → New SSH key检查一下:

你说的都对,but为什么报错了?

看报错信息中是

代码语言:javascript
复制
https://github.com/helloworldtang/GPT_teacher-3.37M-cn.git

配置的SSH Key,是不是不匹配?

问题解决。


习惯使用git命令行的同学,操作路径如下:

1、检查本地 SSH 密钥

打开终端,执行:

代码语言:javascript
复制
ls -la ~/.ssh

若存在 id_rsa/id_ed25519(私钥)和 id_rsa.pub/id_ed25519.pub(公钥),跳过步骤 2;否则生成密钥:

2、生成 SSH 密钥

代码语言:javascript
复制
ssh-keygen -t ed25519 -C "your_email@example.com"  # 替换为你的 GitHub 邮箱

按回车默认保存路径,无需设置密码(或按需设置)。

Ed25519 是基于扭曲爱德华曲线(Twisted Edwards Curve) 的椭圆曲线加密(ECC)算法,由 Daniel J. Bernstein 等人设计,是目前最安全、高效的非对称加密 / 签名算法之一,广泛用于 SSH、TLS、密码学库(如 libsodium)、区块链等场景。 Ed25519详解

3、添加 SSH 密钥到 GitHub

  • 复制公钥内容:
代码语言:javascript
复制
cat ~/.ssh/id_ed25519.pub  # 若用 RSA 则是 cat ~/.ssh/id_rsa.pub

4、修改本地仓库的远程地址为 SSH

代码语言:javascript
复制
cd /Users/username/GPT_teacher-3.37M-cn
git remote set-url origin git@github.com:helloworldtang/GPT_teacher-3.37M-cn.git

5、测试 SSH 连接

代码语言:javascript
复制
ssh -T git@github.com

若输出 Hi helloworldtang! You've successfully authenticated...,说明配置成功。

6、重新推送

代码语言:javascript
复制
git push origin feature/gpu-train-accel

success.

完成。

tips: GitHub 推荐使用 SSH 协议进行 Git 操作,无需每次输入密码,且稳定性更高。

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2025-12-19,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 的数字化之路 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档