Git:使用Git时如何解决权限被拒绝(公钥)错误?

发布于 2024-08-29 15:28:38 字数 534 浏览 4 评论 0 原文

我使用的是 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 但仍然出现相同的错误。

I'm on Mac Snow Leopard and I just installed git.

I just tried

git clone [email protected]:cakebook.git

but that gives me this error:

Initialized empty Git repository in `/Users/username/Documents/cakebook/.git/`
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

What am I missing?
I've also tried doing ssh-keygen with no passphase but still same error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(30

美人迟暮 2024-09-05 15:28:39

基本的 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...

摘星┃星的人 2024-09-05 15:28:39

当您尝试使用不同的用户名推送到存储库时,最简单的解决方案是:

 git remote set-url origin https://[email protected]/USERNAME/PROJECTNAME.git

The easiest solution to this, when you are trying to push to a repository with a different username is:

 git remote set-url origin https://[email protected]/USERNAME/PROJECTNAME.git
云雾 2024-09-05 15:28:39

它非常简单。键入以下命令

ssh-keygen -t rsa -b 4096 -C "[email protected]"

生成 SSH 密钥。打开文件并复制内容。转到 GitHub 设置页面,然后单击 SSH 密钥。单击“添加新的 SSH 密钥”,然后将内容粘贴到此处。就是这样:) 您不应该再看到这个问题。

Its pretty straight forward. Type the below command

ssh-keygen -t rsa -b 4096 -C "[email protected]"

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.

岛徒 2024-09-05 15:28:39

我删除了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.

屋顶上的小猫咪 2024-09-05 15:28:39

这就是我最终能够推送到 git


对我来说,我不断得到

[email protected]: Permission denied 
fatal: Could not read from remote 

Please make sure you have the correct access rights
and the repository exists.

所以经过几个小时的研究,我发现在生成您的 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

[email protected]: Permission denied 
fatal: Could not read from remote 

Please make sure you have the correct access rights
and the repository exists.

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

┈┾☆殇 2024-09-05 15:28:38

如果用户之前没有生成 ssh 公钥/私钥对

此信息适用于 theChaw,但可以应用于所有其他支持 SSH pubkey 身份验证的 git 存储库。 (例如,请参阅 [gitolite][1]、gitlab 或 github。)

首先设置您自己的公钥/私钥对集。这
可以使用 DSA 或 RSA,所以基本上您设置的任何密钥都可以使用。
在大多数系统上,您可以使用 ssh-keygen。

  • 首先,您需要 cd 进入 .ssh 目录。打开终端并运行:

<块引用>

cd ~/.ssh && ssh-keygen

  • 接下来您需要将其复制到剪贴板。
  • 在 OS X 上运行:cat id_rsa.pub | pbcopy
  • 在 Linux 上运行:cat id_rsa.pub | x剪辑
  • 在 Windows 上(通过 Cygwin/Git Bash)运行:cat id_rsa.pub |剪辑
  • 在 Windows (Powershell) 上运行:Get-Content id_rsa.pub |设置剪贴板(感谢@orion elenzil)
  • 通过网站将您的密钥添加到您的帐户。
  • 最后设置您的 .gitconfig。
  • git config --global user.name "bob"
  • git config --global user.email bob@...
    (不要忘记重新启动命令行以确保重新加载配置)

这就是您应该很好地克隆和签出的内容。

更多信息可以在 https://help.github.com/articles/generate-ssh 找到-keys(感谢@Lee Whitney)
[1]: https://github.com/sitaramc/gitolite

-

如果用户有生成 ssh 公钥/私钥对集之前

  • 检查哪个密钥已在您的 github 或 gitlab 帐户设置上授权
  • 确定必须从您的本地计算机关联哪个相应的私钥

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.)

First start by setting up your own public/private key pair set. This
can use either DSA or RSA, so basically any key you setup will work.
On most systems you can use ssh-keygen.

  • First you'll want to cd into your .ssh directory. Open up the terminal and run:

cd ~/.ssh && ssh-keygen

  • Next you need to copy this to your clipboard.
  • On OS X run: cat id_rsa.pub | pbcopy
  • On Linux run: cat id_rsa.pub | xclip
  • On Windows (via Cygwin/Git Bash) run: cat id_rsa.pub | clip
  • On Windows (Powershell) run: Get-Content id_rsa.pub | Set-Clipboard (Thx to @orion elenzil)
  • Add your key to your account via the website.
  • Finally setup your .gitconfig.
  • git config --global user.name "bob"
  • git config --global user.email bob@...
    (don't forget to restart your command line to make sure the config is reloaded)

That's it you should be good to clone and checkout.

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

  • check which key have been authorized on your github or gitlab account settings
  • determine which corresponding private key must be associated from your local computer

eval $(ssh-agent -s)

  • define where the keys are located

ssh-add ~/.ssh/id_rsa

悲歌长辞 2024-09-05 15:28:38

可以通过以下方式完成更广泛的故障排除甚至自动修复:

ssh -vT [email protected]

或者,根据以下评论,我们可以发出:

ssh -vT [email protected]

或用您的组织正在运行的任何 Git 实例替换 gitlab/github。

来源: https://help.github.com/articles/error-permission-拒绝公钥/

More extensive troubleshooting and even automated fixing can be done with:

ssh -vT [email protected]

Alternatively, according to below comments, we could issue:

ssh -vT [email protected]

or substitute gitlab/github with whatever Git Instance your organisation is running.

Source: https://help.github.com/articles/error-permission-denied-publickey/

就是爱搞怪 2024-09-05 15:28:38

当您访问 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.

逆光下的微笑 2024-09-05 15:28:38

github帮助链接帮助我解决了这个问题。看起来 ssh 密钥没有添加到 ssh-agent 中。这就是我最终所做的。

命令 1:

确保 ssh-agent 已启用。该命令在后台启动 ssh-agent:

eval "$(ssh-agent -s)"

命令 2:

将 SSH 密钥添加到 ssh-agent:

ssh-add ~/.ssh/id_rsa

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:

eval "$(ssh-agent -s)"

Command 2:

Add your SSH key to the ssh-agent:

ssh-add ~/.ssh/id_rsa
冰火雁神 2024-09-05 15:28:38

Windows 上的另一种可能性,没有在任何这些答案中涵盖,也没有在有关故障排除的 git 或 github 文档中涵盖:

git 可能使用与您想象的不同的 openssh 可执行文件。

当我尝试从 github 和 ssh.dev.azure.com 克隆或拉取时,我收到权限被拒绝(公钥) 错误,我已按照所有说明操作并验证了我的 SSH 密钥使用 ssh -vT [email protected]ssh -vT [电子邮件受保护]。并且仍然遇到这些错误:

[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

我最终发现问题是 Windows 版的 Git 和 Windows 都有自己的 openssh 版本。此处记录:https://github.com/desktop/desktop/issues/5641

我依赖 Windows ssh-agent 服务来存储我的 ssh 密钥密码,因此 git (及其独立版本的 openssh)无法读取我的私钥。我认为使用此错误消息是一个错误 - 它具有误导性。

修复是:

git config --global core.sshCommand "'C:\Windows\System32\OpenSSH\ssh.exe'"

或者在你的 ~/.gitconfig 中:

[core]
    sshCommand = 'C:\\Windows\\System32\\OpenSSH\\ssh.exe'

也许这很快就会在 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) using ssh -vT [email protected] and ssh -vT [email protected]. And was still getting these errors:

[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

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:

git config --global core.sshCommand "'C:\Windows\System32\OpenSSH\ssh.exe'"

Or in your ~/.gitconfig:

[core]
    sshCommand = 'C:\\Windows\\System32\\OpenSSH\\ssh.exe'

Perhaps this will be fixed in git for Windows soon, but this is the 2nd time I've wasted time on this issue.

很糊涂小朋友 2024-09-05 15:28:38

我正在努力解决同样的问题,这就是我所做的,并且我能够克隆该存储库。我在 Mac 上遵循了此过程。

第一步:检查我们是否已经拥有公共 SSH 密钥。

  1. 打开终端。
  2. 输入 ls -al ~/.ssh 来查看是否存在现有 SSH 密钥:

检查目录列表以查看您是否已有公共 SSH 密钥。默认公共是以下 d_dsa.pub、id_ecdsa.pub、id_ed25519.pub、id_rsa.pub 之一。

如果未找到,请转到步骤 2,否则请按照步骤 3

步骤 2:生成公共 SSH 密钥

  1. 打开终端。
  2. 输入以下命令以及用于 github 的有效电子邮件地址 ssh-keygen -t rsa -b 4096 -C "[电子邮件受保护]"
  3. 您将在终端中看到以下内容正在生成公钥/私钥对。当提示“输入要保存密钥的文件”时,按 Enter 键。这接受默认文件位置。当提示输入要保存密钥的文件 (/Users/you/.ssh/id_rsa) 时:[Press Enter] 只需再次按 Enter 即可。
  4. 出现提示时,“键入安全密码。输入密码(无密码则为空):[键入密码]” 如果您不想再次输入相同的密码,请按 Enter:[再次输入密码] 再次按 Enter

这将生成 id_rsa.pub

第 3 步:将 SSH 密钥添加到 ssh-agent

  1. 终端类型 评估“$(ssh-agent -s)”

  2. 将您的 SSH 密钥添加到 ssh-agent。如果您使用现有的 SSH 密钥而不是生成新的 SSH 密钥,则需要将命令中的 id_rsa 替换为现有私钥文件的名称。输入此命令$ ssh-add -K ~/.ssh/id_rsa

  3. 现在复制 SSH 密钥并将其添加到您的 github 帐户

  4. 在终端中输入此命令以及您的 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.

  1. Open Terminal.
  2. Enter 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

  1. Open Terminal.
  2. Enter the following command with a valid email address that you use for github ssh-keygen -t rsa -b 4096 -C "[email protected]"
  3. You will see the following in your terminal 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 to Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter] Just press enter again.
  4. At the prompt, "Type a secure passphrase. Enter passphrase (empty for no passphrase): [Type a passphrase]" press enter if you don't want to Enter same passphrase again: [Type passphrase again] press enter again

This will generate id_rsa.pub

Step 3: Adding your SSH key to the ssh-agent

  1. Interminal type eval "$(ssh-agent -s)"

  2. 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

  3. Now copy the SSH key and also add it to you github account

  4. In terminal enter this command with your ssh file name pbcopy < ~/.ssh/id_rsa.pub This will copy the file to your clipboard
    Now 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.

独夜无伴 2024-09-05 15:28:38

得到了同样的错误报告。

修复了使用 HTTPS 而不是 SSH 协议的问题。因为我不想为测试电脑设置“SSH 密钥”。

克隆时将 URL 更改为 HTTPS:

git clone https://github.com/USERNAME/REPOSITORY.git

我的问题有点不同:将现有本地存储库添加到远程时,我将 URL 设置为 SSH,方法是

git remote add origin ssh://github.com/USERNAME/REPOSITORY.git

:将 URL 重置为 HTTPS

git remote set-url origin https://github.com/USERNAME/REPOSITORY.git

顺便说一句,您可以使用以下命令检查您的 URL:

git remote -v
origin  https://github.com/USERNAME/REPOSITORY.git (fetch)
origin  https://github.com/USERNAME/REPOSITORY.git (push)

希望这会对像我这样的人有所帮助。 :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:

git clone https://github.com/USERNAME/REPOSITORY.git

My problem is a little bit different: I have the URL set to SSH when adding an existing local repo to remote, by using:

git remote add origin ssh://github.com/USERNAME/REPOSITORY.git

To fix it, reset the URL to HTTPS:

git remote set-url origin https://github.com/USERNAME/REPOSITORY.git

BTW, you may check your URL using the command:

git remote -v
origin  https://github.com/USERNAME/REPOSITORY.git (fetch)
origin  https://github.com/USERNAME/REPOSITORY.git (push)

Hope this will help some one like me. :D

倾城°AllureLove 2024-09-05 15:28:38

这对我有用:

ssh-add ~/.ssh/id_rsa

This works for me:

ssh-add ~/.ssh/id_rsa
深陷 2024-09-05 15:28:38

视觉指南(仅限 Windows)

第 1 部分(共 2 部分)。Git 批处理端

1.1. 打开 git 批处理(下载:https://git-scm.com/downloads)
输入图像描述这里

1.2. 粘贴下面的文本(更改为您的 GitHub 帐户电子邮件

$ ssh-keygen -t rsa -b 4096 -C "[email protected]"

在此处输入图像描述

< strong>1.3. 按 Enter(接受默认文件位置)
输入图像描述此处

1.4。单击Enter两次(或设置 SSH 密钥密码 - Gitbub 密码文档)

> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]

1.5。密钥生成:

您的身份信息已保存在 /c/Users/user/.ssh/id_rsa...

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)
enter image description here

1.2. Paste the text below (Change to your GitHub account email)

$ ssh-keygen -t rsa -b 4096 -C "[email protected]"

enter image description here

1.3. Press Enter (Accepts the default file location)
enter image description here

1.4. Click Enter Twice (Or set SSH key passphrases - Gitbub passphrases docs)

> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]

1.5. The key generate:

Your identification has been saved in /c/Users/user/.ssh/id_rsa...

1.6. Copy the SSH key to your clipboard.

$ clip < ~/.ssh/id_rsa.pub

2 of 2. Github website user side

Under user setting
enter image description here

SSH and GPG keys => New SSH key:
enter image description here

Paste the code from step 1.6
enter image description here

Done :)

enter image description here


If someone doesn't want to use SSH use HTTPS :

enter image description here

Github docs: https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh

虫児飞 2024-09-05 15:28:38

如果您的问题最近(2021 年下半年)突然出现,则可能是由不兼容的哈希算法引起的。

截至本文(2021 年 10 月),Windows 版 Git 的最新版本是 2.33.1(发行说明 ),谁接受了最新的 OpenSSH 8.8p1(发行说明),又是谁已弃用 SHA-1。同时,如果您的远程 Git 存储库仍然坚持 SHA-1,您将无法通过身份验证。

要了解您是否遇到这种情况,请通过以下方式检查您的软件版本:

ssh -V
git --version

然后您应该检查 OpenSSH 8.8/8.8p 发行说明

TL;DR

解决方案 1: 将其添加到您的 ~/.ssh/config 文件中,再次启用 SHA-1:

Host <remote>
    HostkeyAlgorithms +ssh-rsa
    PubkeyAcceptedAlgorithms +ssh-rsa

记住替换 替换为远程存储库的主机名。

解决方案 2:使用 ECDSA 或 Ed25519(而不是 RSA)重新生成密钥对。例如:

ssh-keygen -t ecdsa -C <comment>

记得将 替换为您自己的助记词。然后,将生成的公钥上传到您的远程存储库。


仅供参考,我在访问 Gitee.com 时遇到了此提示消息,该网站在其服务器上使用 golang.org/x/crypto/ssh 并发布了有关此问题的页面 此处(普通话)。

[email protected]: Permission denied (publickey).

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:

ssh -V
git --version

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:

Host <remote>
    HostkeyAlgorithms +ssh-rsa
    PubkeyAcceptedAlgorithms +ssh-rsa

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:

ssh-keygen -t ecdsa -C <comment>

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).

[email protected]: Permission denied (publickey).
昵称有卵用 2024-09-05 15:28:38

如果没有解决问题,请尝试此操作

  1. 生成个人访问令牌(设置 -> 开发者设置 -> 个人访问令牌 -> 生成新令牌
  2. git远程 set-url origin https://@github.com/USERNAME/REPOSITORY.git

注意:如果出现密码弹出窗口,请尝试仅输入令牌(尝试两次)

Please try this if nothing is worked out

  1. Generate personal Access token (Setting -> Developer settings -> Personal access tokens -> Generate new token)
  2. 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)

烟酒忠诚 2024-09-05 15:28:38

请注意(至少对于某些项目)您必须拥有一个带有 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.

吹泡泡o 2024-09-05 15:28:38

这些是我在 Windows 10 中执行的步骤

  1. 打开 Git Bash。

  2. 生成公钥:

    ssh-keygen -t rsa -b 4096 -C "[电子邮件]受保护]
  3. 将生成的密钥复制到剪贴板(类似于 CTRL+C)

    剪辑< 〜/.ssh/id_rsa.pub
    
  4. 浏览器,转到 Github =>简介=>设置=> SSH 和 GPG 密钥 =>添加密钥

  5. 提供键名称并粘贴剪贴板 (CTRL+V)。

  6. 最后,测试您的连接(Git bash)

    ssh -T [电子邮件受保护]
    

在此处输入图像描述

谢谢!

These are the steps I followed in windows 10

  1. Open Git Bash.

  2. Generate Public Key:

    ssh-keygen -t rsa -b 4096 -C "[email protected]"
    
  3. Copy generated key to the clipboard (works like CTRL+C)

    clip < ~/.ssh/id_rsa.pub
    
  4. Browser, go to Github => Profile=> Settings => SSH and GPG keys => Add Key

  5. Provide the key name and paste clipboard (CTRL+V).

  6. Finally, test your connection (Git bash)

    ssh -T [email protected]
    

enter image description here

Thanks!

栀梦 2024-09-05 15:28:38

我遇到了同样的问题,因为我认为 SSHHTTPS 之间的区别是

https://github.com/USERNAME/REPOSITORY.git

ssh://github.com/USERNAME/REPOSITORY.git

因此,我只需更改 https:就从 HTTPS 更改为 SSH: //ssh:// url 末尾没有任何更改。

但事实是:

https://github.com/USERNAME/REPOSITORY.git

[email protected]:USERNAME/REPOSITORY.git

这意味着我将 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:// to ssh:// nothing on the end of the url was changed.

But the truth is:

https://github.com/USERNAME/REPOSITORY.git

[email protected]:USERNAME/REPOSITORY.git

Which means I changed ssh://github.com/USERNAME/REPOSITORY.git to [email protected]:USERNAME/REPOSITORY.git it works.

Stupid error but hope helps someone!

顾北清歌寒 2024-09-05 15:28:38

我的情况略有不同,我登录到远程服务器并在服务器上使用 git,当我运行任何 git 命令时,我收到相同的消息

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

我修复它的方法是通过更改我的文件 /etc/ssh_config苹果。

ForwardAgent no 

ForwardAgent yes

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

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

The way I fixed it was by changing the file /etc/ssh_config on my Mac.
from

ForwardAgent no 

to

ForwardAgent yes
溺渁∝ 2024-09-05 15:28:38

始终检查 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

在那里你可以看到密钥是用以下内容生成的:

ssh-keygen -t ed25519 -C "[email protected]"

所以算法是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:

ssh-keygen -t ed25519 -C "[email protected]"

So algorithm is ed25519 not rsa or anything else.

凑诗 2024-09-05 15:28:38

使用gh的解决方案即Github官方CLI

gh安装

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 CLI

gh 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 mentioned gh in the answers yet

蓝天白云 2024-09-05 15:28:38

我必须将 ssh 密钥复制到根文件夹。
运行 Ubuntu 18.04 的 Google 云计算引擎

sudo cp ~/.ssh/* /root/.ssh/

I had to copy my ssh keys to the root folder.
Google Cloud Compute Engine running Ubuntu 18.04

sudo cp ~/.ssh/* /root/.ssh/
三寸金莲 2024-09-05 15:28:38

您是否处于企业环境?是否有可能您的系统变量最近发生了变化?根据这个答案,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 the identity 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.

笑梦风尘 2024-09-05 15:28:38

伙计们,这对我来说是这样的:

  1. 打开终端并转到用户[参见附图]
  2. 打开 .ssh 文件夹并确保它没有任何像 id_rsa 或 id_rsa.pub 这样的文件,否则有时它不会正确重写文件
  3. git -- version [检查 git 安装和版本]
  4. git config --global user.email "您的电子邮件 ID"
  5. git config --global user.name "您的名字"
  6. git config --list [确保您已设置您的姓名和版本] email]
  7. cd ~/.ssh
  8. ssh-keygen,提示保存文件,允许它
  9. cat ~/.ssh/id_rsa.pub [访问你的公钥&将密钥复制到 gerrit 设置]

注意:您不应该在 Git 中使用 sudo 命令。如果您有充分的理由必须使用 sudo,那么请确保在每个命令中都使用它(此时使用 su 来以 root 身份获取 shell 可能会更好)。如果您在不使用 sudo 的情况下生成 SSH 密钥,然后尝试使用 sudo git push 等命令,则您将不会使用生成的相同密钥

在此处输入图像描述

在此处输入图像描述

Guys this is how it worked for me:

  1. Open terminal and go to user [See attached image]
  2. Open .ssh folder and make sure it doesn't have any file like id_rsa or id_rsa.pub otherwise sometimes it wont properly rewrite files
  3. git --version [Check for git installation and version]
  4. git config --global user.email "your email id"
  5. git config --global user.name "your name"
  6. git config --list [make sure you have set your name & email]
  7. cd ~/.ssh
  8. ssh-keygen, it prompts for saving file, allow it
  9. cat ~/.ssh/id_rsa.pub [Access your public key & copy the key to gerrit settings]

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

enter image description here

enter image description here

秉烛思 2024-09-05 15:28:38

我遇到这个错误是因为我需要给我当前的工作目录权限 700:

chmod -R 700 /home/ec2-user/

I hit this error because I needed to give my present working directory permissions 700:

chmod -R 700 /home/ec2-user/
甜味拾荒者 2024-09-05 15:28:38

在 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.

空气里的味道 2024-09-05 15:28:38

最简单的方法之一

进入终端 -

  git push <Git Remote path> --all

One of the easiest way

go to terminal-

  git push <Git Remote path> --all
你爱我像她 2024-09-05 15:28:38

我帮助了以下操作:

  1. 打开终端 (Git Bash)
  2. 删除目录 .ssh 中的所有文件或重命名并创建新的 .ssh 文件夹。
  3. 请按照说明的步骤进行操作:
    1. 生成新的 SSH 密钥
    2. 将 SSH 密钥添加到 ssh-agent

系统:Windows 10。

I helped the following:

  1. Open Terminal (Git Bash)
  2. Remove all files in directory .ssh or rename and create new .ssh folder.
  3. To follow in the steps of the instructions:
    1. Generating a new SSH key
    2. Adding your SSH key to the ssh-agent

System: Windows 10.

帝王念 2024-09-05 15:28:38

如果您正在使用 POWERSHELL 并且像我一样使用现有私钥运行 git 命令时遇到问题...那么这些说明将派上用场(我刚刚使它工作):

假设您 您的 .ssh 文件夹中已生成私钥“some_key”(例如 ssh-keygen -t rsa -b 4096 -C "[电子邮件受保护]" ) ;然后:

  • 以提升的访问权限/以管理员身份打开 powershell 终端
  • 运行这些命令

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 文件

Host github.com
  User git
  IdentityFile C:\Users\yourUser\.ssh\some_key

如果 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 example ssh-keygen -t rsa -b 4096 -C "[email protected]" ) ; then:

  • Open a powershell terminal with elevated access / as administrator
  • Run these commands

Get-Service -Name ssh-agent | Set-Service -StartupType Manual

Start-Service ssh-agent

  • Add the generated private key to the 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

Host github.com
  User git
  IdentityFile C:\Users\yourUser\.ssh\some_key

If the ssh-agent service is set to run manually, then it must be started up again upon reboot.

Hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文