mik*_*ike 18 git permissions ssh github
从另一个(本地)存储库推送到github帐户后,我似乎失去了对github帐户的权限.我现在收到以下错误:
git push
Permission denied (publickey).fatal:
The remote end hung up unexpectedly
Run Code Online (Sandbox Code Playgroud)
然后,我按照以下步骤重新生成密钥:
ssh-keygen
Set up an ssh on my account for this laptop, using id_rsa.pub
Run Code Online (Sandbox Code Playgroud)
但是,这是不成功的.当我尝试以下代码建议时,我收到以下错误:
ssh-add -l
Could not open a connection to your authentication agent.
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
Ide*_*ind 53
我按照这个分步说明解决了这个问题:
第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.
Run Code Online (Sandbox Code Playgroud)
第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
Run Code Online (Sandbox Code Playgroud)
第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
Run Code Online (Sandbox Code Playgroud)
第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
Run Code Online (Sandbox Code Playgroud)
然后,转到hithub,并执行:
第5步:测试一切
$ ssh -T git@github.com
# Attempts to ssh to github
Run Code Online (Sandbox Code Playgroud)
好的,你会看到
Hi username! You've successfully authenticated, but GitHub does not
# provide shell access.
Run Code Online (Sandbox Code Playgroud)
否则(它发生在我身上),你会看到
Agent admitted failure to sign using the key.
# debug1: No more authentication methods to try.
# Permission denied (publickey).
Run Code Online (Sandbox Code Playgroud)
要解决这个问题
$ ssh-add
# Enter passphrase for /home/you/.ssh/id_rsa: [tippy tap]
# Identity added: /home/you/.ssh/id_rsa (/home/you/.ssh/id_rsa)
Run Code Online (Sandbox Code Playgroud)
原始信息
https://help.github.com/articles/generating-ssh-keys
https://help.github.com/articles/error-agent-admitted-failure-to-sign
小智 5
如果您已经在 ~/.ssh 中有一个公钥(并且已经将该密钥添加到您的 github 帐户),您可能只需要再次将您的密钥加载到 SSH 代理中。
要测试 SSH 代理是否具有密钥,请键入ssh-add -l
If 结果为:
The agent has no identities.
Run Code Online (Sandbox Code Playgroud)
然后只需像这样将您的密钥加载到 SSH 代理中:
ssh-add ~/.ssh/github_rsa
Run Code Online (Sandbox Code Playgroud)
(github_rsa 是我机器上存储的 SSH 密钥的名称。这个文件也可以命名为:id_rsa)
之后,您必须输入密钥的密码(这可能是您登录 github 的密码)。如果您收到这样的消息:
Identity added: /Users/name/.ssh/github_rsa (/Users/cpotzinger/.ssh/github_rsa)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
34240 次 |
最近记录: |