git push error: could not read Username for 'https://github.com': Permission denied

git push error: could not read Username for 'https://github.com': Permission denied

我正在使用 CentOS 7 并尝试推送到 github。首先我使用的是 ssh,但我的系统似乎有一些奇怪的错误,我的 ssh 密钥不断消失(我知道这令人难以置信,但我没有其他解释。)相反,我一直在尝试使用 https,但我无法推送到 github 并且不知道为什么。事情是这样的:

$ git push origin remote
fatal: could not read Username for 'https://github.com': Permission denied

你能帮忙吗?

如果您想使用 https,您需要完整的 url 存储库:

git remote set-url https://<yourLogin>@github.com/<yourLogin>/<yourRepo>

那你可以试试git push.
这将要求您提供 GitHub 帐户密码,除非您已激活 2FA(参见“About Two-Factor Authentication"), in which case you would need to generate first a PAT (Personnal Acces Token).

我已经尝试过,唯一可以制作类似内容的方法是放弃我的 .git 文件的一部分。鉴于 SSH 凭据,如您所说,'disappear',我猜这实际上是错误消息所说的:

fatal: could not read Password 

即,您没有对您尝试读取的文件的读取权限。

现在,正在寻找您主目录中您不可可读的文件:

cd
find -not -readable -print0 | xargs -0 ls -lh

将为您提供有关您的主目录中您的用户无法读取的所有文件的详细信息。通常,您应该只会在那里看到几个锁定文件。我怀疑您的 .ssh 文件夹中或您的 git 存储库中也有一些东西。

问题肯定是我使用的 git 版本有错误。

另外,我和我的团队合作伙伴现在对 Linux 更加熟悉,并且我们认识到使用相同的 .ssh 文件夹(与 root 相同!)我们所有的钥匙都是个坏主意。

无论如何,我们最终停止了对服务器的摆弄(因为我们真的不知道自己在做什么),而是使用 Heroku 部署了我们的网站。不过感谢大家的帮助!