从另一个(本地(存储库推送到 github 帐户后,我似乎失去了对它的权限。 我现在收到以下错误:
git push
Permission denied (publickey).fatal:
The remote end hung up unexpectedly
然后,我执行以下步骤来重新生成密钥:
ssh-keygen
Set up an ssh on my account for this laptop, using id_rsa.pub
然而,这没有成功。 当我尝试以下建议的代码时,我收到以下错误:
ssh-add -l
Could not open a connection to your authentication agent.
有什么想法吗?
我按照以下分步说明解决了这个问题:
步骤 1:检查 SSH 密钥
$ cd ~/.ssh
# Checks to see if there is a directory named ".ssh" in your user directory
# If it says "No such file or directory" skip to step 3. Otherwise continue to step 2.
步骤 2:备份和删除现有 SSH 密钥
$ ls
# Lists all the subdirectories in the current directory
# config id_rsa id_rsa.pub known_hosts
$ mkdir key_backup
# Makes a subdirectory called "key_backup" in the current directory
$ cp id_rsa* key_backup
# Copies the id_rsa keypair into key_backup
$ rm id_rsa*
# Deletes the id_rsa keypair
步骤 3:生成新的 SSH 密钥
$ ssh-keygen -t rsa -C "your_email@youremail.com"
# Creates a new ssh key using the provided email
# Generating public/private rsa key pair.
# Enter file in which to save the key (/home/you/.ssh/id_rsa):
# Enter passphrase (empty for no passphrase): [Type a passphrase]
# Enter same passphrase again: [Type passphrase again]
# Your identification has been saved in /home/you/.ssh/id_rsa.
# Your public key has been saved in /home/you/.ssh/id_rsa.pub.
# The key fingerprint is:
# 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@youremail.com
步骤 4:将 SSH 密钥添加到 GitHub
$ sudo apt-get install xclip
# Downloads and installs xclip
$ xclip -sel clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
然后,转到 GitHub,并执行以下操作:
- 转到您的帐户设置
- 单击左侧边栏中的"SSH 密钥">
- 点击"添加SSH密钥">
- 将您的密钥粘贴到"密钥"字段中
- 点击"添加密钥">
- 通过输入您的 GitHub 密码来确认操作
第 5 步:测试所有内容
$ ssh -T git@github.com
# Attempts to ssh to github
如果确定,您将看到
Hi username! You've successfully authenticated, but GitHub does not
# provide shell access.
否则(它发生在我身上(,你会看到
Agent admitted failure to sign using the key.
# debug1: No more authentication methods to try.
# Permission denied (publickey).
为了解决这个问题
$ ssh-add
# Enter passphrase for /home/you/.ssh/id_rsa: [tippy tap]
# Identity added: /home/you/.ssh/id_rsa (/home/you/.ssh/id_rsa)
原始信息
https://help.github.com/articles/generating-ssh-keys
https://help.github.com/articles/error-agent-admitted-failure-to-sign
如果你在 ~/.ssh 中已经有一个公钥(并且已经将该密钥添加到你的 github 帐户(,你可能只需要再次将密钥加载到 SSH 代理中。
若要测试 SSH 代理是否具有密钥,请键入 ssh-add -l
如果结果是:
The agent has no identities.
然后,只需将密钥加载到 SSH 代理中,如下所示:
ssh-add ~/.ssh/github_rsa
(github_rsa是我的计算机上存储的 SSH 密钥的名称。除其他外,此文件也可以命名为:id_rsa(
之后,您必须输入密钥的密码短语(这可能是您登录github的密码(。如果您收到如下消息:
Identity added: /Users/name/.ssh/github_rsa (/Users/cpotzinger/.ssh/github_rsa)
做一个$ ssh-add
这对我也有帮助解决 gitlab 的以下问题
jovimac-2:work joviano$ git clone git@git.xyz.com:bjetfweb.git
Cloning into 'bjetfweb'...
Access denied.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
您必须使用以下命令在服务器上导出密钥
ssh-copy-id user@host
ssh-agent
应该在你的 ssh-add 之前运行。如果你在Linux下,你可以把这一行放在/etc/rc.local
eval $(ssh-agent)
编辑:现在我知道你使用Windows,所以看到这个线程:让ssh代理使用git从Windows命令shell运行