【问题标题】:Permissions error github (ssh key not recognized)权限错误 github(ssh 密钥无法识别)
【发布时间】:2012-03-22 14:02:37
【问题描述】:

从另一个(本地)存储库推送到 github 帐户后,我似乎失去了对 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.

有什么想法吗?

【问题讨论】:

    标签: git permissions ssh github


    【解决方案1】:

    您必须使用命令在服务器上导出您的密钥

    ssh-copy-id user@host
    

    ssh-agent 应该在您的 ssh-add 之前运行。 如果您在 Linux 下,可以将此行放在 /etc/rc.local 中:

    eval $(ssh-agent)
    

    编辑:现在我知道你使用的是 windows,所以请看这个帖子:Getting ssh-agent to work with git run from windows command shell

    【讨论】:

    • 感谢您的提示——我在 windows 上使用 git-bash 界面,并且 ssh-copy-id 未被识别为命令。
    • 因此,您必须手动从id_rsa.pub 复制生成的行并将其附加到服务器上的文件~user/.ssh/authorized_keys
    【解决方案2】:

    我按照这个分步说明解决了这个问题:

    第 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
    

    然后,去hithub,然后做:

    1. 转到您的帐户设置
    2. 点击左侧边栏中的“SSH Keys”
    3. 点击“添加 SSH 密钥”
    4. 将您的密钥粘贴到“密钥”字段中
    5. 点击“添加密钥”
    6. 输入您的 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

    【讨论】:

    • 不好意思,路径怎么输入?我的路径是 C:\Documents and Settings\admin\.ssh 文件夹。输入路径的格式是什么?
    • 在你的 Mac 上而不是 'sudo apt-get install xclip' 你可能需要运行 'brew install homebrew/emacs/xclip-mode' 来代替
    • ssh-add 命令为我做了这件事。我相信这是由于 macOS Sierra 中的新行为所必需的。
    【解决方案3】:

    如果您已经在 ~/.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)
    

    【讨论】:

      【解决方案4】:

      做一个$ 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.
      

      【讨论】:

        猜你喜欢
        • 2022-01-14
        • 1970-01-01
        • 1970-01-01
        • 2013-08-12
        • 1970-01-01
        • 2013-09-12
        • 1970-01-01
        • 2020-02-11
        • 1970-01-01
        相关资源
        最近更新 更多