【问题标题】:Why is a cap deploy giving Permission denied (publickey)?为什么上限部署会给予权限被拒绝(公钥)?
【发布时间】:2011-12-19 14:22:33
【问题描述】:

好的,我对某些事情感到困惑...我可以很好地提交到我的 github 存储库,但是当我尝试从本地文件夹到暂存服务器执行 cap deploy 时,我得到 Permission denied (publickey).

如果我运行ssh git@github.com,我实际上会收到错误PTY allocation request failed on channel 0

所以这里有问题。

如果我运行ssh -vT git@github.com,我会得到:

OpenSSH_5.6p1, OpenSSL 0.9.8r 8 Feb 2011
debug1: Reading configuration data /Users/myuser/.ssh/config
debug1: Reading configuration data /etc/ssh_config
debug1: Applying options for *
debug1: Connecting to github.com [207.97.227.239] port 22.
debug1: Connection established.
debug1: identity file /Users/myuser/.ssh/id_rsa type 1
debug1: identity file /Users/myuser/.ssh/id_rsa-cert type -1
debug1: identity file /Users/myuser/.ssh/id_dsa type -1
debug1: identity file /Users/myuser/.ssh/id_dsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.1p1 Debian-5github2
debug1: match: OpenSSH_5.1p1 Debian-5github2 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.6
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /Users/myuser/.ssh/known_hosts:2
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: /Users/myuser/.ssh/github_rsa
debug1: Remote: Forced command: gerve technomad
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Remote: Forced command: gerve technomad
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([207.97.227.239]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0
Hi technomad! You've successfully authenticated, but GitHub does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 2384, received 2888 bytes, in 0.1 seconds
Bytes per second: sent 42630.8, received 51643.3
debug1: Exit status 1

我的密钥在 ~/.ssh 文件夹中,那是什么问题,如果有关键问题,为什么我能够提交到存储库??

更新: 当我进入我的 .ssh 文件夹时,我确实注意到了一些东西。当我安装 Github for Mac 时创建了一个新的密钥对……为什么它不能只使用我不知道的现有密钥对。

【问题讨论】:

    标签: git ssh capistrano ssh-keys public-key


    【解决方案1】:

    我必须做到以下几点:

       $ ssh-add -D   #remove existing identities
       $ ssh-agent    #copy the lines & run them
       $ ssh-add      #uses the output from above
    

    【讨论】:

    • 这是问题的准确答案。无需在舞台机器上添加 ssh 密钥。只需运行上面的命令并完成...谢谢@olore
    • 但这背后的原因是什么,这个命令做了什么来解决这个问题?
    • 上述命令将 RSA/DSA 身份添加到身份验证代理,在部署时检查权限。由于某种原因,如果在运行部署命令之前未添加身份,您将收到权限被拒绝错误。对我来说,每当我重新启动计算机时,我都需要输入上述命令才能使其工作。我认为每次重启后我的 ssh 公钥都没有自动添加。因此,我在上述命令之后使用ssh-add -K 将输出添加到钥匙串。之后我的问题就永久解决了。
    • 我在 Debian 中遇到了一个巨大的问题,其密钥名称与 id_rsa 不同。我刚刚做了ssh-add $HOME/.ssh/[key_name]
    • 这对我有用。将文件系统转移到新计算机后出现错误。
    【解决方案2】:

    我有时会收到此错误,我只需键入$ ssh-add -k 以添加我的身份,然后它就可以工作了。不确定为什么会这样或者为什么错误消息没有提示它,但它总是能派上用场!

    【讨论】:

      【解决方案3】:

      我会确保您的登台服务器可以通过 ssh 访问 github。通过登台服务器上的终端运行相同的命令“ssh -vT git@github.com”;这将有助于确定远程计算机上是否是 ssh 问题。

      【讨论】:

      • 这很有效,谢谢:),我忽略了那部分。但是我还是不知道为什么“ssh git@github.com”返回“PTY allocation request failed on channel 0”?
      • 您可以通过 ssh 连接到其他服务器而不会出现该问题吗?
      • 我会看看这个帖子:comments.gmane.org/gmane.os.cygwin/125243。 HTH。
      • 谢谢,你的链接最终让我得到了这个答案stackoverflow.com/questions/3844393/…。引用答案“'PTY 分配请求失败'是关于 GitHub 身份验证的红鲱鱼(这是当他们提供的唯一 SSH 服务是非交互式 Git-over-SSH 时尝试交互式登录 GitHub 的结果;身份验证正在工作,他们只是不提供交互式“shell”服务)。”
      • 请注意,如果您有set :ssh_options, forward_agent: true(这是在 capistrano 中处理键的好方法),这可能是一个红鲱鱼。如果您使用代理转发,即使其他一切正常,您也不一定能够从远程服务器 ssh 到 github,这意味着原始问题可能与本地 ssh 配置有关。
      【解决方案4】:

      我在为 Mac OS X 安装 GitHub 后遇到了同样的问题。应用程序在 ~/.ssh/github_rsa 中创建了一个新的 ssh 私钥并将其添加到 ssh 身份验证代理中。

      检查 ssh 身份验证代理缓存了哪些密钥:

      $ ssh-add -l
      2048 63:0c:a6:51:63:c1:35:76:5d:02:77:97:39:48:0e:4a /Users/jiangxin/.ssh/github_rsa (RSA)
      

      每当您连接到 github.com 或其他 ssh 服务时,都会首先使用此密钥。

      使用以下命令从 ssh-agent 清除缓存的密钥:

      $ ssh-add -D
      

      现在 ssh 客户端应该可以正常工作了,使用在 ~/.ssh/config 或 ~/.ssh/id_rsa 中定义的密钥。

      【讨论】:

        【解决方案5】:

        错误是因为 ssh-add 不知道如何与身份验证代理对话。 该问题可以通过设置SSH_AUTH_SOCK环境变量来解决。

        如果你运行 ssh-agent,你应该得到如下输出:

        SSH_AUTH_SOCK=/tmp/ssh-agVZL13989/agent.13989; export SSH_AUTH_SOCK;
        SSH_AGENT_PID=13990; export SSH_AGENT_PID;
        echo Agent pid 13990;SSH_AUTH_SOCK=/tmp/ssh-agVZL13989/agent.13989; export SSH_AUTH_SOCK;
        SSH_AGENT_PID=13990; export SSH_AGENT_PID;
        echo Agent pid 13990;
        

        执行这个:

        eval $(ssh-agent)
        

        然后:

        ssh-add -D
        

        【讨论】:

        • 亲爱的 Sankalp,您的回答非常简短,应提供一些额外信息以防止其被删除(它已被其他用户标记为删除)
        • 谢谢@furins..我会写一些信息。
        • 为什么是ssh-add -D?这只会删除您的身份。不要认为它会帮助解决问题。
        • 然后使用ssh-add添加回来
        【解决方案6】:

        如果您使用的是 MAC。也许您的 ssh 密钥未添加到身份验证代理中。以下命令将执行此操作

        ssh-add path_to_private_key
        

        例如

        ssh-add ~/.ssh/id_rsa
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-03-11
          • 2019-11-24
          • 2014-11-08
          • 2012-01-18
          • 2012-04-25
          相关资源
          最近更新 更多