简体   繁体   English

“权限被拒绝(公钥)。” Git错误

[英]“Permission denied (publickey).” Git error

I have registered the ssh key for my machine on github and verified that it works by typing ssh git@github.com and receiving a response indicating successful authentication. 我已经在github上为我的机器注册了ssh密钥,并通过键入ssh git@github.com并收到指示成功认证的响应来验证它是否可以正常工作。

However, when I try and push my source code on the machine to my git repository I receive 但是,当我尝试将计算机上的源代码推送到git存储库时,会收到

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

I have looked at other threads with the same problem as me and they all seem to recommend registering the ssh key with github which I have already done. 我看过其他与我有相同问题的线程,它们似乎都建议向我已经完成的github注册ssh密钥。

Edit: The contents of my .git/config file on my workstation 编辑:我的工作站上.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

Any ideas? 有任何想法吗?

The url line for the origin remote appears to be missing a username. origin远程url行似乎缺少用户名。 The reason why you are getting Permission Denied is because SSH is defaulting to your local system username, since none was specified. 之所以被拒绝权限,是因为SSH默认为您的本地系统用户名,因为未指定任何用户名。 Unless your local username happens to be identical to the remote username, it will reject the login as your public key is not associated with an account by that name. 除非您的本地用户名与远程用户名相同,否则它将拒绝登录,因为您的公钥没有与此名称关联的帐户。

The remote URL should either be in the format ssh://<username>@<hostname>/path/to/git/repo/ , or in Github's case, git@github.com:<username>/<repo name>.git . 远程URL的格式应为ssh://<username>@<hostname>/path/to/git/repo/ ,对于Github, git@github.com:<username>/<repo name>.git

You can change your origin url with the following command: 您可以使用以下命令更改原始网址:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM