git - "Permission denied (publickey)."Git错误

标签 git github ssh

我已经在 github 上为我的机器注册了 ssh key ,并通过键入 ssh git@github.com 验证它是否有效。接收认证成功的响应。

但是,当我尝试将机器上的源代码推送到我的 git 存储库时,我收到

Permission denied (publickey).
fatal: The remote end hung up unexpectedly

我查看了与我有相同问题的其他线程,他们似乎都建议使用我已经完成的 github 注册 ssh key 。

编辑:我的工作站上的 .git/config 文件的内容
[core]  
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = ssh://github.com/OSU-Net/list_expiration
[branch "master"]
    remote = origin
    merge = refs/heads/master

有任何想法吗?

最佳答案

url origin 的行远程似乎缺少用户名。您获得 Permission Denied 的原因是因为 SSH 默认使用您的本地系统用户名,因为没有指定任何用户名。除非您的本地用户名恰好与远程用户名相同,否则它将拒绝登录,因为您的公钥未与该名称的帐户相关联。

远程 URL 的格式应为 ssh://<username>@<hostname>/path/to/git/repo/ ,或者在 Github 的情况下,git@github.com:<username>/<repo name>.git .

您可以使用以下命令更改原始 url:

git remote set-url origin git@github.com:OSU-Net/list_expiration.git

关于git - "Permission denied (publickey)."Git错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25127940/

相关文章:

Git重命名检测空文件

android - 如何为现有的Github存储库添加Gradle支持?

python - ssh-copy-id 有时会挂起

ssh - 等待提权提示超时

git - 错误 : src refspec does not match any

git - 为什么一个新的本地分支会立即开始跟踪创建它的本地分支,我该如何关闭它?

windows - Windows批处理下无法使用 "git.exe fetch origin"内的管道

github - 在 Github 的表格中使用 Markdown 图标?

windows - Github:为什么我需要它?

linux - 用于从多个主机删除文件的 Shell 脚本