【问题标题】:Github: Permission denied (publickey) but I got "You've successfully authenticated" messageGithub:权限被拒绝(公钥),但我收到“您已成功验证”消息
【发布时间】:2015-06-13 09:13:40
【问题描述】:

我已经完成的步骤: https://help.github.com/articles/generating-ssh-keys/ 完全按照。

$ eval "$(ssh-agent -s)"
Agent pid 31944
$ ssh-add
Enter passphrase for /home/centos7/.ssh/id_rsa:
Identity added: /home/centos7/.ssh/id_rsa (/home/centos7/.ssh/id_rsa)

$ ssh-add -l
4096 ab:4d:23:23:99:ce:bb:9d:9f:9e:f9:b2:c8:1a:cd:f7 /home/centos7/.ssh/id_rsa (RSA)

但是,当我跑步时

$ git clone git@github.com:privateRepo/repo.git

Cloning into 'repo'...
The authenticity of host 'github.com (192.30.252.130)' can't be established.
RSA key fingerprint is 56:27:ac:a5:36:28:2d:36:23:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.252.130' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

下面是我运行的输出

$ ssh -Tv git@github.com

OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /home/centos7/.ssh/config
debug1: /home/centos/.ssh/config line 1: Applying options for *github.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 56: Applying options for *
debug1: Connecting to github.com [192.30.252.131] port 22.
debug1: Connection established.
debug1: identity file /home/centos7/.ssh/id_rsa type 1
debug1: identity file /home/centos7/.ssh/id_rsa-cert type -1
debug1: identity file /home/centos7/.ssh/id_dsa type -1
debug1: identity file /home/centos7/.ssh/id_dsa-cert type -1
debug1: identity file /home/centos7/.ssh/id_ecdsa type -1
debug1: identity file /home/centos7/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/centos7/.ssh/id_ed25519 type -1
debug1: identity file /home/centos7/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1
debug1: Remote protocol version 2.0, remote software version libssh-0.7.0
debug1: no match: libssh-0.7.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: kex: ecdh-sha2-nistp256 need=20 dh_need=20
debug1: kex: ecdh-sha2-nistp256 need=20 dh_need=20
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: RSA 56:27:ac:a5:36:28:2d:36:23:1b:56:4d:eb:df:a6:48
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /home/centos/.ssh/known_hosts:1
Warning: Permanently added the RSA host key for IP address '192.30.252.131' to the list of known hosts.
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: Offering RSA public key: /home/centos7/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 535
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([192.30.252.131]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending env LC_CTYPE = UTF-8
Hi tomkim! You've successfully authenticated, but GitHub does not provide shell access.
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 4128, received 2040 bytes, in 0.5 seconds
Bytes per second: sent 8000.8, received 3953.9
debug1: Exit status 1

如上一行所示,Hi tomkim! You've successfully authenticated, but GitHub does not provide shell access. 这意味着我已经未经验证,但为什么我不能克隆我的 repo?

更新: 我可以在我的主目录中克隆,但是当我尝试使用 sudo 时它不起作用,它发生在我的 /var/www/html/ 文件夹中

$ sudo git clone git@github.privateRepo/repo.git 克隆到“回购”... 警告:将 IP 地址“192.30.252.131”的 RSA 主机密钥永久添加到已知主机列表中。 权限被拒绝(公钥)。 致命:无法从远程存储库读取。

请确保您拥有正确的访问权限 并且存储库存在。

$ git clone git@github.privateRepo/repo.git 克隆到“回购”... 远程:计数对象:4741,完成。 远程:总计 4741(增量 0),重用 0(增量 0),打包重用 4741 接收对象:100% (4741/4741), 30.30 MiB | 5.83 MiB/s,完成。 解决增量:100% (1451/1451),完成。 [centos@ip-172-31-12-124 ~]$ ll 共 4 个 drwxrwxr-x。 12 centos centos 4096 Jun 15 04:16 repo

我知道我可以使用 HTTPS 进行克隆,但我想解决这个问题,有人可以帮忙吗?

【问题讨论】:

  • 您是要克隆自己的存储库还是其他人的存储库?
  • 是的。我确实尝试了我自己的回购也不能。上面的例子是一个私人仓库。 git clone 在 ssh 中不起作用。
  • 当你说你试图克隆privateRepo/repo.git时,privateRepo应该是一个用户组织,而不是一个存储库。像git@github.com:user/project.git 这样的东西更准确。你这样做吗?
  • 是的。我正在这样做。我尝试克隆我自己的 repo 也无法正常工作……centos 7 设置是否可能不同?这是我第一次使用 centos7,我的 Mac 运行良好...
  • 我认为 CentOS 并不重要。您是否总是收到“永久添加 IP 地址‘192.30.252.131’的 RSA 主机密钥”消息?它在您的 sshgit clone 命令的输出中。

标签: git github ssh


【解决方案1】:

答案是相关的用户权限问题。我需要为当前用户设置正确的文件夹权限。

对于 git sudo 的问题,可以在下面的链接中找到答案:

https://help.github.com/articles/error-permission-denied-publickey/#should-the-sudo-command-be-used-with-git

感谢克里斯调查这个问题。

【讨论】:

  • 在完成ls -la 之后,我发现通过从 FTP 创建文件夹,它的用户名是不同的,而从命令提示符下它是不同的。通过 FTP 创建文件夹,然后它的工作正常。
  • 您能否详细说明“我需要为当前用户设置正确的文件夹权限”?你到底做了什么来解决这个问题?
  • e.g 我以tom登录,我需要将文件夹的所有者设置为tom
【解决方案2】:

将 SSH 公钥复制到 SSH 目录下。

cd ~/.ssh
cat id_rsa.pub

复制发布密钥并将其粘贴到 GIT“设置”页面下的“SSH 和 GPG 密钥”下。

点击你的头像 --> "设置" --> "SSH and GPG key" ,现在添加复制文本。

【讨论】:

  • 欢迎来到 Stackoverflow。如果您签出How to Answer 页面以备将来在堆栈溢出时的努力会更好。 -谢谢
【解决方案3】:

使用这个 https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/

然后获取您生成的密钥(以 ssh-rsa 或其他类型开头) 转到您的 git 用户面板 -> SSH 和 GPG 密钥 -> 新 SSH 密钥 -> 粘贴您的密钥(用任何填充标题)然后按添加 SSH 密钥

将修复。

祝你好运。

【讨论】:

    【解决方案4】:
    1. 打开你的终端并逐步运行以下命令

      $ ssh-add -l -E sha256

    2. 你会得到这样的东西

      256 SHA256:CMY4Hfwu5CPf0xxxxx/kzsluFSyr7HhkL2b5XXXXX email@example.com (ED25519)

    3. 进入 .ssh 目录

      ~$ cd ~/.ssh

    4. 使用您的 ID (ED25519)

      运行此命令

      $ cat id_ed25519.pub

    5. 你会得到这样的东西(我已经改变了密钥) ssh-ed25519

      AAAAC3NzaC1lZDI1NTE5XXXXINN9c+lXXXXXXQd1sSo2I4trq6rD/2lbBd3OrYPDoG email@example.com

    6. 第5点

      复制整个内容
    7. 打开你的 github 账户 -> 进入设置 -> SSH 和 GPG 密钥

    8. 单击新的 SSH 密钥按钮

    9. 从第 5 点粘贴完整的密钥并在 SSH 中添加任何标题

    你就完成了!!!

    【讨论】:

      猜你喜欢
      • 2018-03-05
      • 2012-10-08
      • 2012-01-18
      • 2012-04-25
      相关资源
      最近更新 更多