bash Github 权限被拒绝:ssh 添加代理没有身份
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26505980/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Github permission denied: ssh add agent has no identities
提问by Dark
This is my first time accessing GitHub and I'm not experienced using a console. I am on a MacBook using Bash. When I try to access GitHub, I get this:
这是我第一次访问 GitHub,我没有使用控制台的经验。我在使用 Bash 的 MacBook 上。当我尝试访问 GitHub 时,我得到以下信息:
git clone [email protected]:dhulihan/league-of-legends-data-scraper.git
Cloning into 'league-of-legends-data-scraper'...
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I've tried following the instructions on Github page about permission being denied.
我已经尝试按照 Github 页面上关于权限被拒绝的说明进行操作。
When I use ssh -vT [email protected]
, I get the following:
当我使用时ssh -vT [email protected]
,我得到以下信息:
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to github.com [192.30.252.129] port 22.
debug1: Connection established.
debug1: identity file /Users/XXXX/.ssh/id_rsa type -1
debug1: identity file /Users/XXXX/.ssh/id_rsa-cert type -1
debug1: identity file /Users/XXXX/.ssh/id_dsa type -1
debug1: identity file /Users/XXXX/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version libssh-0.6.0
debug1: no match: libssh-0.6.0
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-sha1 none
debug1: kex: client->server aes128-ctr hmac-sha1 none
debug1: sending SSH2_MSG_KEXDH_INIT
debug1: expecting SSH2_MSG_KEXDH_REPLY
debug1: Server host key: RSA 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /Users/XXXX/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /Users/XXXX/.ssh/id_rsa
debug1: Trying private key: /Users/XXXX/.ssh/id_dsa
debug1: No more authentication methods to try.
Permission denied (publickey).
Next, eval "$(ssh-agent -s)"
returns "Agent pid 2314",
however ssh-add -l
returns "The agent has no identities."
接下来,eval "$(ssh-agent -s)"
返回“代理 pid 2314”,但ssh-add -l
返回“代理没有身份”。
And that is where I am stuck.
这就是我被困的地方。
回答by John Doedoe
Full details in this answer.
此答案中的完整详细信息。
In summary, when ssh-add -l
returns “The agent has no identities”, it means that keys used by ssh
(stored in files such as ~/.ssh/id_rsa
, ~/.ssh/id_dsa
, etc.) are either missing, they are not known to ssh-agent
, which is the authentication agent, or that their permissions are set incorrectly (for example, world?writable).
总之,当ssh-add -l
返回“代理不具有标识”,它是指通过使用该密钥ssh
(存储在文件中,例如~/.ssh/id_rsa
,~/.ssh/id_dsa
等)是丢失,它们不是已知的ssh-agent
,这是认证代理,或者他们的权限设置不正确(例如,world?writable)。
If your keys are missing or if you have not generated any, use ssh-keygen -t rsa
, then ssh-add
to add them.
如果您的密钥丢失或您尚未生成任何密钥,请使用ssh-keygen -t rsa
, thenssh-add
添加它们。
If keys exist but are not known to ssh-agent
(like if they are in a non-standard folder), use ssh-add /path/to/my-non-standard-ssh-folder/id_rsa
to add?them.
如果键存在但不知道ssh-agent
(比如它们在非标准文件夹中),请使用ssh-add /path/to/my-non-standard-ssh-folder/id_rsa
添加?它们。
See this answerif you are having trouble with ssh-add
or?ssh-agent
.
见这个答案,如果您有困难ssh-add
或?ssh-agent
.
回答by Boltun Oreh
try this:
尝试这个:
ssh-add ~/.ssh/id_rsa
worked for me
对我来说有效
回答by metakungfu
THE 2019 ANSWER for macOS Sierra & High Sierra & Catalina:
macOS Sierra 和 High Sierra 和 Catalina 的 2019 年答案:
PS: most of the other answers will have you to create a new ssh key ... but you don't need to do that :)
PS:大多数其他答案都会让你创建一个新的 ssh 密钥......但你不需要这样做:)
As described in detail on https://openradar.appspot.com/27348363, macOS/OS X till Yosemite used to remember SSH keys added by command ssh-add -K <key>
正如在https://openradar.appspot.com/27348363上详细描述的,macOS/OS X 直到 Yosemite 用来记住通过命令添加的 SSH 密钥ssh-add -K <key>
So here are the 4 steps i had to take in order for it to work:
因此,这是我必须采取的 4 个步骤才能使其正常工作:
1:ssh-add ~/.ssh/PATH_TO_YOUR_SSH_PRIVATE_KEY (e.g. ~/.ssh/id_rsa)
1:ssh-add ~/.ssh/PATH_TO_YOUR_SSH_PRIVATE_KEY (e.g. ~/.ssh/id_rsa)
2:Add the following in ~/.ssh/config
2:添加以下内容~/.ssh/config
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile PATH_TO_YOUR_SSH_PRIVATE_KEY (e.g. ~/.ssh/id_rsa)
3:make sure to remove any gitconfig entry that use osxkeychain helper:
3:确保删除任何使用 osxkeychain helper 的 gitconfig 条目:
https://github.com/gregory/dotfiles/commit/e38000527fb1a82b577f2dcf685aeefd3b78a609#diff-6cb0f77b38346e0fed47293bdc6430c6L48
4:restart your terminal for it to take effect.
4:重启终端使其生效。
回答by Fed Zee
I have been stucked a while on the same problem, which I eventually resolved.
我在同样的问题上被困了一段时间,我最终解决了。
My problem: I could not execute any push. I could check & see my remote (using git remote -v
), but when I executed git push origin master
, it returned : Permission denied (publickey). fatal: Could not read from remote repository.
and so.
我的问题:我无法执行任何推送。我可以检查并查看我的遥控器(使用git remote -v
),但是当我执行时git push origin master
,它返回 :Permission denied (publickey). fatal: Could not read from remote repository.
等等。
How I solved it :
我是如何解决的:
- I generated a keyusing
ssh-keygen -t rsa
. Entering a name for the key file (when asked) was useless. - I could then add the key (to git):
ssh-add /Users/federico/.ssh/id_rsa
, which successfully returnedIdentity added: /Users/myname/.ssh/id_rsa (/Users/myname/.ssh/id_rsa)
- I added the SSH key to githubusing this help page.
- Having tried all the commands in Github's 'Permission denied publickey' help page, only the
ssh-add -l
command worked / seemed useful (after having ran the previous steps), it successfully returned my key. The last stepshows you where to check your public key on your GitHub page. And this command will help you check all your keys :ls -al ~/.ssh
.
- 我使用
ssh-keygen -t rsa
. 输入密钥文件的名称(当被询问时)是没有用的。 - 然后我可以添加密钥(到 git):
ssh-add /Users/federico/.ssh/id_rsa
,它成功返回Identity added: /Users/myname/.ssh/id_rsa (/Users/myname/.ssh/id_rsa)
- 我使用此帮助页面将 SSH 密钥添加到 github。
- 尝试了 Github 的“权限被拒绝的公钥”帮助页面中的所有命令后,只有该
ssh-add -l
命令有效/似乎有用(在运行了前面的步骤之后),它成功返回了我的密钥。最后一步向您展示了在 GitHub 页面上检查公钥的位置。此命令将帮助您检查所有密钥:ls -al ~/.ssh
。
Then the push command eventually worked !
然后 push 命令最终奏效了!
I hope this will help ! Best luck to all.
我希望这个能帮上忙 !祝大家好运。
回答by zouhair khallaf
Run the following commands:
运行以下命令:
ssh-keygen -t rsa
ssh-add /Users/*yourUserNameHere*/.ssh/id_rsa**
pbcopy < ~/.ssh/id_rsa.pub**
Go to your Github account : https://github.com/settings/profile
转到您的 Github 帐户:https: //github.com/settings/profile
1) Click : SSH and GPG keys
1) 点击:SSH 和 GPG 密钥
2) New SSH Key and Past it there
2)新的SSH密钥并将其粘贴在那里
3) Add SSH Key
3) 添加 SSH 密钥
Done!
完毕!
回答by Sultan Ali
first of all you need to go in your ssh directory
for this type following command in your terminal in mac or whatever you use in window
首先,你需要在你的 ssh 目录中进入你的 ssh 目录
,在 mac 的终端或你在窗口中使用的任何命令
cd ~/.ssh
now it is in the ssh
here you can find all you ssh key/files related to your all projects. now, type the following command to show you if any ssh key available
现在它在 ssh 中
,您可以在这里找到与所有项目相关的所有 ssh 密钥/文件。现在,键入以下命令以显示是否有可用的 ssh 密钥
ls
this will show you all available ssh, in my case there were two
now, you will need to start an agent to add a ssh in it. For this type following command
这将向您显示所有可用的 ssh,就我而言,
现在有两个,您需要启动一个代理以在其中添加一个 ssh。对于这种类型的以下命令
eval "$(ssh-agent -s)"
now last but not least you will add a ssh in this agent type following command
现在最后但并非最不重要的是,您将按照以下命令在此代理类型中添加 ssh
ssh-add ~/.ssh/your-ssh
replace
代替
replace your-ssh with your ssh file name which you got a list form second step
ls command
将 your-ssh 替换为您的 ssh 文件名,您在第二步中获得了列表形式
ls command
回答by user9253738
This could cause for any new terminal, the agent id is different. You need to add the Private key for the agent
这可能导致任何新终端的代理 ID 不同。您需要为代理添加私钥
$ ssh-add <path to your private key>
回答by Varghese Cherian
One additional element that I realized is that typically .ssh folder is created in your root folder in Mac OS X /Users/. If you try to use ssh -vT [email protected] from another folder it will give you an error even if you had added the correct key.
我意识到的另一个元素是,通常 .ssh 文件夹是在 Mac OS X /Users/ 的根文件夹中创建的。如果您尝试从另一个文件夹使用 ssh -vT [email protected],即使您添加了正确的密钥,它也会给您一个错误。
You need to add the key again (ssh-add 'correct path to id_rsa') from the current folder to authenticate successfully (assuming that you have already uploaded the key to your profile in Git)
您需要从当前文件夹再次添加密钥(ssh-add 'correct path to id_rsa')以成功进行身份验证(假设您已经将密钥上传到您在 Git 中的配置文件中)
回答by Nacho Cornejo
This worked for me:chmod 700 .ssh
chmod 600 .ssh/id_rsa
chmod 644 .ssh/id_rsa.pub
这对我有用:chmod 700 .ssh
chmod 600 .ssh/id_rsa
chmod 644 .ssh/id_rsa.pub
Then, type this:
ssh-add ~/.ssh/id_rsa
然后,键入:
ssh-add ~/.ssh/id_rsa
回答by Deborah
I had this issue after restoring a hard drive from a backup.
从备份恢复硬盘驱动器后,我遇到了这个问题。
My problem:I could check & see my remote (using git remote -v), but when I executed git push origin master, it returned : Permission denied (publickey). fatal: Could not read from remote repository.
我的问题:我可以检查和查看我的遥控器(使用 git remote -v),但是当我执行 git push origin master 时,它返回:Permission denied (publickey)。致命:无法从远程存储库读取。
I already had an SSH folder and SSH keys, and adding them via Terminal (ssh-add /path/to/my-ssh-folder/id_rsa
) successfully added my identity, but I still couldn't push and still got the same error. Generating a new key was a bad idea for me, because it was tied to other very secure permissions on AWS.
我已经有一个 SSH 文件夹和 SSH 密钥,通过终端 ( ssh-add /path/to/my-ssh-folder/id_rsa
)添加它们成功添加了我的身份,但我仍然无法推送并且仍然出现相同的错误。生成新密钥对我来说是个坏主意,因为它与 AWS 上的其他非常安全的权限相关联。
It turned out the link between the key and my Github profile had broken.
结果发现密钥和我的 Github 个人资料之间的链接已经断开。
Solution:Re-adding the key to Github in Profile > Settings > SSH and GPG keys resolved the issue.
解决方案:在配置文件 > 设置 > SSH 和 GPG 密钥中将密钥重新添加到 Github 解决了该问题。
Also:My account had 2-factor authentication set up. When this is the case, if Terminal requests credentials, use your username - but NOT your Github password. For 2-factor authentication, you need to use your authentication code (for me, this was generated by Authy on my phone, and I had to copy it into Terminal for the pw).
另外:我的帐户设置了 2 因素身份验证。在这种情况下,如果终端请求凭据,请使用您的用户名 - 但不是您的 Github 密码。对于 2 因素身份验证,您需要使用您的身份验证代码(对我来说,这是由我手机上的 Authy 生成的,我必须将其复制到终端以获取密码)。