[英]git@github.com: Permission denied (publickey)
I created a new remote repository and tried to use git push -u origin master
command to push my local files into the new repository the first time after I add
it and commit
it.我创建了一个新的远程存储库,并尝试在
add
并commit
后第一次使用git push -u origin master
命令将我的本地文件推送到新存储库中。 However, it pops up this 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.
git@github.com: Permission denied (publickey). fatal: Could not read from remote repository.
. . How can I fix this fatal error?
我该如何解决这个致命错误?
I've tried this我试过这个
How to solve Permission denied (publickey) error when using Git? 使用 Git 时如何解决 Permission denied (publickey) 错误? It seems that the question in this link happens in the first time using git. I've used my git for a while, do I still need to follow this solution?
这个链接的问题好像是第一次使用git,我用了一段时间的git,还需要按照这个解决吗? Can anyone gives me a more specific solution?
谁能给我一个更具体的解决方案?
This the fatal error that I got这是我得到的致命错误
C:\Users\ASUS\Desktop\React-Practice App\my-app>git status
On branch master
nothing to commit, working tree clean
C:\Users\ASUS\Desktop\React-Practice App\my-app>git push -u origin master
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
You're accessing GitHub through SSH.您正在通过 SSH 访问 GitHub。 First generate an SSH key pair;
首先生成一个SSH密钥对; then add the public key to GitHub.
然后将公钥添加到 GitHub。
Generate key pair:生成密钥对:
ssh-keygen -t rsa -b 4096 -C “youremail@example.com”
See more at https://help.github.com/en/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent and https://help.github.com/en/articles/adding-a-new-ssh-key-to-your-github-account在https://help.github.com/en/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent和https://help.github.com查看更多/en/articles/adding-a-new-ssh-key-to-your-github-account
Had the same issue even after adding ssh keys on github.即使在 github 上添加 ssh 密钥后也有同样的问题。
Fixed it by running this command通过运行此命令修复它
ssh -vT git@github.com
When I had this problem, I ended up having a typo in my git remote origin url.当我遇到这个问题时,我最终在我的 git remote origin url 中有一个错字。 Maybe you can double check that everything is spelled correctly without any additional unintended keystrokes?
也许您可以仔细检查所有内容是否拼写正确,而没有任何额外的意外击键?
On Windows there are sometimes multiple version of SSH installed.在 Windows 上,有时会安装多个版本的 SSH。
It results in conflict when using git:使用git时会产生冲突:
git@github.com: Permission denied (publickey) . git@github.com:权限被拒绝(公钥) 。
To resolve it, just point the correct version in environment variable:要解决它,只需在环境变量中指向正确的版本:
setx /m GIT_SSH C:\Windows\System32\OpenSSH\ssh.exe setx /m GIT_SSH C:\Windows\System32\OpenSSH\ssh.exe
I had this problem because I used a non-standard location for my key like @Mon did.我遇到了这个问题,因为我像@Mon 一样为我的密钥使用了一个非标准位置。 In my case, I did not use the default file name because I have more than one key on my system.
就我而言,我没有使用默认文件名,因为我的系统上有多个键。 So it's not possible to resolve it simply by moving or renaming.
因此,不能简单地通过移动或重命名来解决它。
The solution is to edit or create ~/.ssh/config
(OpenSSH docs for config
and Configuring the Location of Identity Keys ) to contain the following:解决方案是编辑或创建
~/.ssh/config
(用于config
和配置身份密钥位置的OpenSSH 文档)以包含以下内容:
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/github-key
Do not edit line 3 to reflect your own username.不要编辑行3,以反映自己的用户名。 The username should be
git
(see github docs ).用户名应该是
git
(参见github 文档)。
Edit line 4 to reflect the location of your key.编辑第 4 行以反映密钥的位置。
If you already have a config
file, it would be worthwhile having a look at what's there before futzing around.如果您已经有一个
config
文件,那么在四处走动之前看看那里有什么是值得的。 It never hurts to make a copy before editing.在编辑之前制作副本永远不会有什么坏处。
The above assumes that you have created the key, put it on github, that you actually do have permissions, and everything else is as it should be, but still encountering error.上述假设您已经创建的关键,把它放在github上,你实际上确实有权限,其他一切都是理所应当的,但仍然遇到错误。
I was having the worst time getting this setup and had the same error pop up.我在进行此设置时遇到了最糟糕的情况,并且弹出了相同的错误。
How I fixed my issue was not having the .git
folder as root and using another user to access it by using sudo
.我如何解决我的问题是没有
.git
文件夹作为 root 并使用另一个用户使用sudo
访问它。 I changed the folder permission to the user:我将文件夹权限更改为用户:
chown -R user:user .git/
The issue for me was that I was on a new PC, trying to access the same account as my other computer.对我来说,问题是我在一台新电脑上,试图访问与我的另一台电脑相同的帐户。 It's not enough to create a new SSH, you also need to register it in your GitHub profile.
创建一个新的 SSH 是不够的,您还需要在您的 GitHub 配置文件中注册它。 Once I did, problem solved itself.
一旦我这样做了,问题就自行解决了。
I believe the best method copying the public key content from ~./ssh
folder is clip
command.我相信从
~./ssh
文件夹复制公钥内容的最佳方法是clip
命令。 Since selecting manually and then copying may introduce additional spaces etc.由于手动选择然后复制可能会引入额外的空间等。
Here are the steps I would follow.以下是我将遵循的步骤。
ls -lah ~/.ssh
in CMD: dir/W %USERPROFILE%\.ssh
在 CMD 中:
dir/W %USERPROFILE%\.ssh
cat ~/.ssh/id_xxxxx.pub | clip
xxxxx could be ed25519
or rsa
xxxxx 可以是
ed25519
或rsa
in CMD: type %USERPROFILE%\.ssh\id_rsa.pub | clip
在 CMD 中:
type %USERPROFILE%\.ssh\id_rsa.pub | clip
type %USERPROFILE%\.ssh\id_rsa.pub | clip
(first one is preferred). (首选第一个)。
ssh-keygen -t ed25519 -C "your_email@example.com
or要么
ssh-keygen -t rsa -b 4096 -C "your_email@example.com
and then do the step 2.然后执行第 2 步。
clip
clip
复制的内存内容NOTE: Same steps will work with BitBucket, GitLab and Azure repos.注意:相同的步骤适用于 BitBucket、GitLab 和 Azure 存储库。
I had the same issue even after adding ssh keys on github.即使在 github 上添加 ssh 密钥后,我也遇到了同样的问题。 Previously I was using "CMD" in Windows.
以前我在 Windows 中使用“CMD”。 Then I changed to "Git Bash" and my issue was resolved.
然后我改为“Git Bash”,我的问题就解决了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.