Git:使用Git时如何解决权限被拒绝(公钥)错误?
我使用的是 Mac Snow Leopard,并且刚刚安装了 git
。
我刚刚尝试过,
git clone [email protected]:cakebook.git
但这给了我这个错误:
Initialized empty Git repository in `/Users/username/Documents/cakebook/.git/`
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
我错过了什么?
我也尝试过在没有 passphase 的情况下执行 ssh-keygen
但仍然出现相同的错误。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(30)
基本的 GIT 指令没有提及 SSH 密钥的内容。按照上面的一些链接,我找到了一个 git 帮助页面,它逐步解释了如何针对各种操作系统执行此操作(该链接将检测您的操作系统并相应地重定向):
http://help.github.com/set-up-git-redirect/
它遍历了 GITHub 所需的所有内容,并且给出了详细的解释,例如“为什么在创建 RSA 密钥时添加密码”。我想我会发布它,以防它对其他人有帮助......
The basic GIT instructions did not make a reference to the SSH key stuff. Following some of the links above, I found a git help page that explains, step-by-step, exactly how to do this for various operating systems (the link will detect your OS and redirect, accordingly):
http://help.github.com/set-up-git-redirect/
It walks through everything needed for GITHub and also gives detailed explanations such as "why add a passphrase when creating an RSA key." I figured I'd post it, in case it helps someone else...
当您尝试使用不同的用户名推送到存储库时,最简单的解决方案是:
The easiest solution to this, when you are trying to push to a repository with a different username is:
它非常简单。键入以下命令
生成 SSH 密钥。打开文件并复制内容。转到 GitHub 设置页面,然后单击 SSH 密钥。单击“添加新的 SSH 密钥”,然后将内容粘贴到此处。就是这样:) 您不应该再看到这个问题。
Its pretty straight forward. Type the below command
Generate the SSH key. Open the file and copy the contents. Go to GitHub setting page , and click on SSH key . Click on Add new SSH key, and paste the contents here. That's it :) You shouldn't see the issue again.
我删除了node_modules/package-lock.json和yarn.lock文件。再次运行
npm i
。这为我解决了这个问题。I deleted node_modules/ package-lock.json and yarn.lock files. Ran
npm i
again. This resolved the issue for me.这就是我最终能够推送到 git
对我来说,我不断得到
所以经过几个小时的研究,我发现在生成您的 ssh 密钥 和 让你的Windows代理识别你的密钥我为解决问题所做的最后一件事是更新 git 存储库中的 ssh 密钥对于那个项目。
因此,您需要登录您的 git hub 帐户,然后转到您想要推送到的存储库,然后在设置中查找安全性,您可以在其中添加 ssh 密钥。对我来说,密钥存储在 .ssh/id_ed123939.pub 中
This is how I was finally able to push to git
For me, I keep on getting
So after hours of research, I discovered that after generating your ssh key and making your windows agent recognise your key the last thing I did to fix my issue was to update the ssh-key in the git repo for that project.
So you would log in to your git hub account then go to the repo you want to push to then in the settings look for security that's where you can add your ssh key. For me, the key is stored in a .ssh/id_ed123939.pub
如果用户之前没有生成 ssh 公钥/私钥对
此信息适用于 theChaw,但可以应用于所有其他支持 SSH pubkey 身份验证的 git 存储库。 (例如,请参阅 [gitolite][1]、gitlab 或 github。)
更多信息可以在 https://help.github.com/articles/generate-ssh 找到-keys(感谢@Lee Whitney)
[1]: https://github.com/sitaramc/gitolite
-
如果用户有生成 ssh 公钥/私钥对集之前
eval $(ssh-agent -s )
ssh-add ~/.ssh/id_rsa
If the user has not generated a ssh public/private key pair set before
This info is working on theChaw but can be applied to all other git repositories which support SSH pubkey authentications. (See [gitolite][1], gitlab or github for example.)
Further information can be found at https://help.github.com/articles/generating-ssh-keys (thanks to @Lee Whitney)
[1]: https://github.com/sitaramc/gitolite
-
If the user has generated a ssh public/private key pair set before
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa
可以通过以下方式完成更广泛的故障排除甚至自动修复:
或者,根据以下评论,我们可以发出:
或用您的组织正在运行的任何 Git 实例替换 gitlab/github。
来源: https://help.github.com/articles/error-permission-拒绝公钥/
More extensive troubleshooting and even automated fixing can be done with:
Alternatively, according to below comments, we could issue:
or substitute gitlab/github with whatever Git Instance your organisation is running.
Source: https://help.github.com/articles/error-permission-denied-publickey/
当您访问 SSH URL(读/写)而不是 Git 只读 URL 但您没有对该存储库的写访问权限时,可能会发生此错误。
有时您只想克隆自己的存储库,例如部署到服务器。在这种情况下,您实际上只需要只读访问权限。但由于这是您自己的存储库,因此 GitHub 可能会显示 SSH URL(如果您愿意的话)。在这种情况下,如果您的远程主机的公钥不在您的 GitHub SSH 密钥中,您的访问将被拒绝,这是预期会发生的。
一个等效的情况是,当您尝试克隆其他人的存储库时,您无权使用 SSH URL 对其进行写入访问。
总之,如果您的目的只是克隆存储库,请使用 HTTPS URL (
https://github.com/{user_name}/{project_name}.git
) 而不是 SSH URL ([电子邮件受保护]:{user_name }/{project_name}.git
),这避免了(不必要的)公钥验证。更新:GitHub 现在将 HTTPS 显示为默认协议,这一举措可能会减少可能的 SSH URL 滥用。
This error can happen when you are accessing the SSH URL (Read/Write) instead of Git Read-Only URL but you have no write access to that repo.
Sometimes you just want to clone your own repo, e.g. deploy to a server. In this case you actually only need READ-ONLY access. But since that's your own repo, GitHub may display SSH URL if that's your preference. In this situation, if your remote host's public key is not in your GitHub SSH Keys, your access will be denied, which is expected to happen.
An equivalent case is when you try cloning someone else's repo to which you have no write access with SSH URL.
In a word, if your intent is to clone-only a repo, use HTTPS URL (
https://github.com/{user_name}/{project_name}.git
) instead of SSH URL ([email protected]:{user_name}/{project_name}.git
), which avoids (unnecessary) public key validation.Update: GitHub is displaying HTTPS as the default protocol now and this move can probably reduce possible misuse of SSH URLs.
github帮助链接帮助我解决了这个问题。看起来 ssh 密钥没有添加到 ssh-agent 中。这就是我最终所做的。
命令 1:
确保 ssh-agent 已启用。该命令在后台启动 ssh-agent:
命令 2:
将 SSH 密钥添加到 ssh-agent:
The github help link helped me sort out this problem. Looks like the ssh key was not added to the ssh-agent. This is what I ended up doing.
Command 1:
Ensure ssh-agent is enabled. The command starts the ssh-agent in the background:
Command 2:
Add your SSH key to the ssh-agent:
Windows 上的另一种可能性,没有在任何这些答案中涵盖,也没有在有关故障排除的 git 或 github 文档中涵盖:
git 可能使用与您想象的不同的 openssh 可执行文件。
当我尝试从 github 和 ssh.dev.azure.com 克隆或拉取时,我收到
权限被拒绝(公钥)
错误,我已按照所有说明操作并验证了我的 SSH 密钥使用ssh -vT [email protected]
和ssh -vT
[电子邮件受保护]。并且仍然遇到这些错误:
我最终发现问题是 Windows 版的 Git 和 Windows 都有自己的 openssh 版本。此处记录:https://github.com/desktop/desktop/issues/5641
我依赖 Windows ssh-agent 服务来存储我的 ssh 密钥密码,因此 git (及其独立版本的 openssh)无法读取我的私钥。我认为使用此错误消息是一个错误 - 它具有误导性。
修复是:
或者在你的 ~/.gitconfig 中:
也许这很快就会在 Windows 的 git 中修复,但这是我第二次在这个问题上浪费时间。
Another possibility on Windows, which is not covered in any of these answers, and is not covered in the git or github docs on troubleshooting:
git may be using a different openssh executable than you think it is.
I was receiving the
Permission denied (public key)
error when trying to clone or pull from github and ssh.dev.azure.com, and I'd followed all the instructions and verified that my SSH keys were setup correctly (from SSH's standpoint) usingssh -vT [email protected]
andssh -vT [email protected]
. And was still getting these errors:I eventually figured out that the problem is that Git for Windows, and Windows, both have their own versions of openssh. This is documented here: https://github.com/desktop/desktop/issues/5641
I was relying on the Windows ssh-agent service to store my ssh key passphrases, so git (with it's separate version of openssh) couldn't read my private keys. I consider it a bug that this error message is used - it's misleading.
The fix was:
Or in your ~/.gitconfig:
Perhaps this will be fixed in git for Windows soon, but this is the 2nd time I've wasted time on this issue.
我正在努力解决同样的问题,这就是我所做的,并且我能够克隆该存储库。我在 Mac 上遵循了此过程。
第一步:检查我们是否已经拥有公共 SSH 密钥。
检查目录列表以查看您是否已有公共 SSH 密钥。默认公共是以下 d_dsa.pub、id_ecdsa.pub、id_ed25519.pub、id_rsa.pub 之一。
如果未找到,请转到步骤 2,否则请按照步骤 3
步骤 2:生成公共 SSH 密钥
ssh-keygen -t rsa -b 4096 -C "[电子邮件受保护]"
正在生成公钥/私钥对
。当提示“输入要保存密钥的文件”时,按 Enter 键。这接受默认文件位置。当提示输入要保存密钥的文件 (/Users/you/.ssh/id_rsa) 时:[Press Enter]
只需再次按 Enter 即可。“键入安全密码。输入密码(无密码则为空):[键入密码]”
如果您不想再次输入相同的密码,请按 Enter:[再次输入密码]
再次按 Enter这将生成
id_rsa.pub
第 3 步:将 SSH 密钥添加到 ssh-agent
终端类型
评估“$(ssh-agent -s)”
将您的 SSH 密钥添加到 ssh-agent。如果您使用现有的 SSH 密钥而不是生成新的 SSH 密钥,则需要将命令中的 id_rsa 替换为现有私钥文件的名称。输入此命令
$ ssh-add -K ~/.ssh/id_rsa
现在复制 SSH 密钥并将其添加到您的 github 帐户
在终端中输入此命令以及您的 ssh 文件名
pbcopy < ~/.ssh/id_rsa.pub
这会将文件复制到剪贴板现在打开你的github帐户转到设置>; SSH 和 GPG 密钥 >新的 SSH 密钥 输入标题并从剪贴板粘贴密钥并保存。瞧,你已经完成了。
I was struggling with the same problem that's what I did and I was able to clone the repo. I followed this procedure for Mac.
First Step: Checking if we already have the public SSH key.
ls -al ~/.ssh
to see if existing SSH keys are present:Check the directory list to see if you already have a public SSH key. Default public is one of the following d_dsa.pub, id_ecdsa.pub, id_ed25519.pub, id_rsa.pub.
If you don't find then go to step 2 otherwise follow step 3
Step 2: Generating public SSH key
ssh-keygen -t rsa -b 4096 -C "[email protected]"
Generating public/private rsa key pair
. When it prompts to"Enter a file in which to save the key,"
press Enter. This accepts the default file location. When it prompts toEnter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]
Just press enter again."Type a secure passphrase. Enter passphrase (empty for no passphrase): [Type a passphrase]"
press enter if you don't want toEnter same passphrase again: [Type passphrase again]
press enter againThis will generate
id_rsa.pub
Step 3: Adding your SSH key to the ssh-agent
Interminal type
eval "$(ssh-agent -s)"
Add your SSH key to the ssh-agent. If you are using an existing SSH key rather than generating a new SSH key, you'll need to replace id_rsa in the command with the name of your existing private key file. Enter this command
$ ssh-add -K ~/.ssh/id_rsa
Now copy the SSH key and also add it to you github account
In terminal enter this command with your ssh file name
pbcopy < ~/.ssh/id_rsa.pub
This will copy the file to your clipboardNow open you github account Go to Settings > SSH and GPG keys > New SSH key Enter title and paste the key from clipboard and save it. Voila you're done.
得到了同样的错误报告。
修复了使用 HTTPS 而不是 SSH 协议的问题。因为我不想为测试电脑设置“SSH 密钥”。
克隆时将 URL 更改为 HTTPS:
我的问题有点不同:将现有本地存储库添加到远程时,我将 URL 设置为 SSH,方法是
:将 URL 重置为 HTTPS:
顺便说一句,您可以使用以下命令检查您的 URL:
希望这会对像我这样的人有所帮助。 :D
Got the same error report.
Fixed with using the HTTPS instead of the SSH protocol. Since I don't want to set "SSH keys" for a test PC.
Change URL to HTTPS when clone:
My problem is a little bit different: I have the URL set to SSH when adding an existing local repo to remote, by using:
To fix it, reset the URL to HTTPS:
BTW, you may check your URL using the command:
Hope this will help some one like me. :D
这对我有用:
This works for me:
视觉指南(仅限 Windows)
第 1 部分(共 2 部分)。Git 批处理端
1.1. 打开 git 批处理(下载:https://git-scm.com/downloads)

1.2. 粘贴下面的文本(更改为您的 GitHub 帐户
电子邮件
)< strong>1.3. 按 Enter(接受默认文件位置)

1.4。单击Enter两次(或设置 SSH 密钥密码 - Gitbub 密码文档)
1.5。密钥生成:
1.6。 将 SSH 密钥复制到剪贴板。
$剪辑< ~/.ssh/id_rsa.pub
2 of 2. Github 网站用户端
用户设置
SSH 和 GPG 密钥
=> 新的 SSH 密钥:粘贴步骤

1.6
中的代码完成:)
如果有人不想使用 SSH
使用 HTTPS
:Github 文档: https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh
Visual guide (Windows Only)
1 of 2. Git batch side
1.1. Open git batch (Download: https://git-scm.com/downloads)

1.2. Paste the text below (Change to your GitHub account
email
)1.3. Press Enter (Accepts the default file location)

1.4. Click Enter Twice (Or set SSH key passphrases - Gitbub passphrases docs)
1.5. The key generate:
1.6. Copy the SSH key to your clipboard.
$ clip < ~/.ssh/id_rsa.pub
2 of 2. Github website user side
Under

user setting
SSH and GPG keys
=> New SSH key:Paste the code from step

1.6
Done :)
If someone doesn't want to use SSH
use HTTPS
:Github docs: https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh
如果您的问题最近(2021 年下半年)突然出现,则可能是由不兼容的哈希算法引起的。
截至本文(2021 年 10 月),Windows 版 Git 的最新版本是 2.33.1(发行说明 ),谁接受了最新的 OpenSSH 8.8p1(发行说明),又是谁已弃用 SHA-1。同时,如果您的远程 Git 存储库仍然坚持 SHA-1,您将无法通过身份验证。
要了解您是否遇到这种情况,请通过以下方式检查您的软件版本:
然后您应该检查 OpenSSH 8.8/8.8p 发行说明。
TL;DR
解决方案 1: 将其添加到您的
~/.ssh/config
文件中,再次启用 SHA-1:记住替换
替换为远程存储库的主机名。解决方案 2:使用 ECDSA 或 Ed25519(而不是 RSA)重新生成密钥对。例如:
记得将
替换为您自己的助记词。然后,将生成的公钥上传到您的远程存储库。仅供参考,我在访问 Gitee.com 时遇到了此提示消息,该网站在其服务器上使用
golang.org/x/crypto/ssh
并发布了有关此问题的页面 此处(普通话)。If your problem appears out of the blue recently (the latter half of 2021), it may have been caused by incompatible hash algorithms.
As of this post (Oct 2021), the latest version of Git for windows is 2.33.1 (release note), who has embraced the latest OpenSSH 8.8p1 (release note), who in turn has deprecated SHA-1. Meanwhile, if your remote Git repository still sticks to SHA-1, you'll fail the authentication.
To see whether you could have fallen into this case, check the version of your software by:
Then you should check the "Potentially-incompatible changes" section of OpenSSH 8.8/8.8p release note.
TL;DR
Solution 1: Enable SHA-1 again by adding this to your
~/.ssh/config
file:Remember to replace
<remote>
with the hostname of your remote repository.Solution 2: Regenerate your key pair using ECDSA or Ed25519, instead of RSA. For example:
Remember to replace
<comment>
with your own mnemonic phrase. Then, upload the generated public key to your remote repository.FYI, I encountered this prompt message when accessing Gitee.com, who uses
golang.org/x/crypto/ssh
on their server and has posted a page on this issue here (in Mandarin).如果没有解决问题,请尝试此操作
设置 -> 开发者设置 -> 个人访问令牌 -> 生成新令牌
)git远程 set-url origin https://@github.com/USERNAME/REPOSITORY.git
注意:如果出现密码弹出窗口,请尝试仅输入令牌(尝试两次)
Please try this if nothing is worked out
Setting -> Developer settings -> Personal access tokens -> Generate new token
)git remote set-url origin https://<TOEKN>@github.com/USERNAME/REPOSITORY.git
Note: If a password popup comes, try to enter the token only (try twice)
请注意(至少对于某些项目)您必须拥有一个带有 ssh 密钥的 github 帐户。
查看身份验证代理中列出的密钥 (ssh-add -l)
(如果您没有看到任何密钥,请使用 ssh-add /path/to/your/key 添加现有密钥之一(例如:ssh-add ~/.ssh/id_rsa))
(如果您没有任何密钥,请先创建一个。请参阅:http://rcsg-gsir.imsb-dsgi.nrc-cnrc.gc.ca/documents/internet/node31.html 或只是 google ssh-keygen)
验证您拥有与您的 github 帐户关联的密钥:
转到:https://github.com/settings/ssh
您应该至少看到一个密钥,其哈希密钥与您一分钟前键入 ssh-add -l 时看到的哈希之一相匹配。
如果没有,请添加一个,然后重试。
Note that (at least for some projects) you must have a github account with an ssh key.
Look at the keys listed in your authentication agent (ssh-add -l)
(if you don't see any, add one of your existing keys with ssh-add /path/to/your/key (eg: ssh-add ~/.ssh/id_rsa))
(if you don't have any keys, first create one. See: http://rcsg-gsir.imsb-dsgi.nrc-cnrc.gc.ca/documents/internet/node31.html or just google ssh-keygen)
To verify that you have a key associated with your github account:
Go to: https://github.com/settings/ssh
You should see at least one key with a hash key matching one of the hashes you saw when you typed ssh-add -l just a minute ago.
If you don't, add one, then try again.
这些是我在 Windows 10 中执行的步骤
打开 Git Bash。
生成公钥:
将生成的密钥复制到剪贴板(类似于 CTRL+C)
浏览器,转到 Github =>简介=>设置=> SSH 和 GPG 密钥 =>添加密钥
提供键名称并粘贴剪贴板 (CTRL+V)。
最后,测试您的连接(Git bash)
谢谢!
These are the steps I followed in windows 10
Open Git Bash.
Generate Public Key:
Copy generated key to the clipboard (works like CTRL+C)
Browser, go to Github => Profile=> Settings => SSH and GPG keys => Add Key
Provide the key name and paste clipboard (CTRL+V).
Finally, test your connection (Git bash)
Thanks!
我遇到了同样的问题,因为我认为 SSH 和 HTTPS 之间的区别是
https://github.com/USERNAME/REPOSITORY.git
ssh://github.com/USERNAME/REPOSITORY.git
因此,我只需更改
https:就从 HTTPS 更改为 SSH: //
到ssh://
url 末尾没有任何更改。但事实是:
这意味着我将
ssh://github.com/USERNAME/REPOSITORY.git
更改为[电子邮件受保护]:USERNAME/REPOSITORY.git
它有效。愚蠢的错误,但希望能帮助别人!
I met the same issue because of I was thought the difference between SSH and HTTPS is
https://github.com/USERNAME/REPOSITORY.git
ssh://github.com/USERNAME/REPOSITORY.git
So I changed from HTTPS to SSH just by changing
https://
tossh://
nothing on the end of the url was changed.But the truth is:
Which means I changed
ssh://github.com/USERNAME/REPOSITORY.git
to[email protected]:USERNAME/REPOSITORY.git
it works.Stupid error but hope helps someone!
我的情况略有不同,我登录到远程服务器并在服务器上使用 git,当我运行任何 git 命令时,我收到相同的消息
我修复它的方法是通过更改我的文件 /etc/ssh_config苹果。
从
到
I had a slight different situation, I was logged on to a remote server and was using git on the server, when I ran any git command I got the same message
The way I fixed it was by changing the file /etc/ssh_config on my Mac.
from
to
始终检查 GitHub 上的 SSH 密钥生成过程,而不是某些过时的博客
https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generate-a -new-ssh-key-and-adding-it-to-the-ssh-agent
在那里你可以看到密钥是用以下内容生成的:
所以算法是ed25519而不是rsa或其他任何东西。
ALWAYS CHECK GITHUB FOR SSH-KEYS GENERATION PROCEDUR, NOT SOME OUTDATED BLOG
https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
There you can see that keys are generated with:
So algorithm is ed25519 not rsa or anything else.
使用
gh
的解决方案即Github官方CLIgh安装
brew install gh
gh 登录或通过 cli 进行身份验证
gh auth login
repo clone
gh repo clone/
示例:
gh repo clone keshavdulal/sample-repo
咆哮:当 git clone 突然决定不再工作时,我也很头疼,而且我没有耐心或脑力来重新学习 ssh /公钥/密码学从头开始只是为了克隆一个我已经可以访问的奇怪的存储库。同样令人惊讶的是,还没有人在答案中提到
gh
Solution using
gh
i.e. Github's official CLIgh installation
brew install gh
gh login or authentication via cli
gh auth login
repo clone
gh repo clone <username or orgname>/<repo-name>
Example:
gh repo clone keshavdulal/sample-repo
Rant: I too was bashing my head when
git clone
suddenly decided not to work anymore and I don't have the patience or brainpower to relearn ssh/public keys/cryptography from scratch just to clone a freaking repo I already have access to. Also surprised no one mentionedgh
in the answers yet我必须将 ssh 密钥复制到根文件夹。
运行 Ubuntu 18.04 的 Google 云计算引擎
I had to copy my ssh keys to the root folder.
Google Cloud Compute Engine running Ubuntu 18.04
您是否处于企业环境?是否有可能您的系统变量最近发生了变化?根据这个答案,ssh密钥位于<代码>%HOMEDRIVE%%HOMEPATH%\.ssh\id_rsa.pub。因此,如果
%HOMEDRIVE%
最近发生了更改,git 不知道在哪里查找您的密钥,因此也不知道所有身份验证内容。尝试运行
ssh -vT [电子邮件受保护]
。记下身份文件
所在的位置。对我来说,这不是指向我的正常\Users\MyLogin
,而是指向网络驱动器,因为在网络级别推送的环境变量发生了更改。解决方案是什么?由于我的新
%HOMEDRIVE%
与本地文件具有相同的权限,因此我只是将 .ssh 文件夹移到那里,然后就到此为止了。Are you in a corporate environment? Is it possible that your system variables have recently changed? Per this SO answer, ssh keys live at
%HOMEDRIVE%%HOMEPATH%\.ssh\id_rsa.pub
. So if%HOMEDRIVE%
recently changed, git doesn't know where to look for your key, and thus all of the authentication stuff.Try running
ssh -vT [email protected]
. Take note of where theidentity file
is located. For me, that was pointing not to my normal\Users\MyLogin
but rather to a network drive, because of a change to environment variables pushed at the network level.The solution? Since my new
%HOMEDRIVE%
has the same permissions as my local files, I just moved my .ssh folder there, and called it a day.伙计们,这对我来说是这样的:
注意:您不应该在 Git 中使用 sudo 命令。如果您有充分的理由必须使用 sudo,那么请确保在每个命令中都使用它(此时使用 su 来以 root 身份获取 shell 可能会更好)。如果您在不使用 sudo 的情况下生成 SSH 密钥,然后尝试使用 sudo git push 等命令,则您将不会使用生成的相同密钥
Guys this is how it worked for me:
Note: You should not be using the sudo command with Git. If you have a very good reason you must use sudo, then ensure you are using it with every command (it's probably just better to use su to get a shell as root at that point). If you generate SSH keys without sudo and then try to use a command like sudo git push, you won't be using the same keys that you generated
我遇到这个错误是因为我需要给我当前的工作目录权限 700:
I hit this error because I needed to give my present working directory permissions 700:
在 Windows 上,确保所有应用程序都同意 HOME。令人惊讶的是,Msys 不会为你做这件事。我必须设置一个环境变量,因为 ssh 和 git 似乎无法就我的 .ssh 目录所在位置达成一致。
On Windows, make sure all your apps agree on HOME. Msys will surprisingly NOT do it for you. I had to set an environment variable because ssh and git couldn't seem to agree on where my .ssh directory was.
最简单的方法之一
进入终端 -
One of the easiest way
go to terminal-
我帮助了以下操作:
.ssh
中的所有文件或重命名并创建新的.ssh
文件夹。系统:Windows 10。
I helped the following:
.ssh
or rename and create new.ssh
folder.System: Windows 10.
如果您正在使用 POWERSHELL 并且像我一样使用现有私钥运行 git 命令时遇到问题...那么这些说明将派上用场(我刚刚使它工作):
假设您 您的
.ssh
文件夹中已生成私钥“some_key”(例如ssh-keygen -t rsa -b 4096 -C "[电子邮件受保护]"
) ;然后:Get-Service -Name ssh-agent | Set-Service -StartupType Manual
Start-Service ssh-agent
ssh-add C:\Users\yourUser\.ssh\some_key< /code>
克隆远程存储库时,请在命令中添加
-c core.sshCommand
选项,以便设置用于在远程存储库上进行身份验证的自定义 ssh 命令。例如。
git clone -c core.sshCommand="ssh -i C:\\Users\\yourUser\\.ssh\\some_key" [email protected]:REMOTE_REPO.git
之后,您应该能够毫无问题地从存储库中拉取和推送。
或者,可以使用以下内容配置 ~/.ssh/config 文件
如果 ssh-agent 服务设置为手动运行,则必须在重新启动时再次启动它。
希望这有帮助
If you are using POWERSHELL and were having issues to run git commands with an existing private key like me... then these instructions will come in handy (I just made it work):
Assuming you already have a private key generated "some_key" in your
.ssh
folder (for examplessh-keygen -t rsa -b 4096 -C "[email protected]"
) ; then:Get-Service -Name ssh-agent | Set-Service -StartupType Manual
Start-Service ssh-agent
ssh-add C:\Users\yourUser\.ssh\some_key
When cloning the remote repo add the
-c core.sshCommand
option in the command in order to set a custom ssh command for authenticating on the remote repo.EG.
git clone -c core.sshCommand="ssh -i C:\\Users\\yourUser\\.ssh\\some_key" [email protected]:REMOTE_REPO.git
After that you should be able to pull and push from the repo with no issues.
Alternatively, one can configure the ~/.ssh/config file with the following contents
If the ssh-agent service is set to run manually, then it must be started up again upon reboot.
Hope this helps