V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
YK46PTT
V2EX  ›  问与答

服务器 git clone 提示 Permission denied,用同样的 key 却在 MacBook 可以克隆下来,请大家提供下思路

  •  
  •   YK46PTT · 2017-04-17 20:11:11 +08:00 · 2672 次点击
    这是一个创建于 2779 天前的主题,其中的信息可能已经有所发展或是发生改变。

    用 Bitbucket 托管代码,服务器 git clone [email protected]:xxx/xxx.git 提示

    Permission denied (publickey).
    fatal: Could not read from remote repository.
    

    ssh -v [email protected]

    结果如下

    OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013
    debug1: Reading configuration data /etc/ssh/ssh_config
    debug1: /etc/ssh/ssh_config line 56: Applying options for *
    debug1: Connecting to bitbucket.org [104.192.143.1] port 22.
    debug1: Connection established.
    debug1: identity file /home/root/.ssh/id_rsa type 1
    debug1: identity file /home/root/.ssh/id_rsa-cert type -1
    debug1: identity file /home/root/.ssh/id_dsa type -1
    debug1: identity file /home/root/.ssh/id_dsa-cert type -1
    debug1: identity file /home/root/.ssh/id_ecdsa type -1
    debug1: identity file /home/root/.ssh/id_ecdsa-cert type -1
    debug1: identity file /home/root/.ssh/id_ed25519 type -1
    debug1: identity file /home/root/.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 conker_1.0.288-e9ef8ea app-152
    debug1: no match: conker_1.0.288-e9ef8ea app-152
    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: [email protected] need=20 dh_need=20
    debug1: kex: [email protected] need=20 dh_need=20
    debug1: sending SSH2_MSG_KEX_ECDH_INIT
    debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
    debug1: Server host key: RSA 97:8c:1b:f2:6f:14:6b:5c:3b:ec:aa:46:46:74:7c:40
    debug1: Host 'bitbucket.org' is known and matches the RSA host key.
    debug1: Found key in /home/root/.ssh/known_hosts:1
    debug1: ssh_rsa_verify: signature correct
    debug1: SSH2_MSG_NEWKEYS sent
    debug1: expecting SSH2_MSG_NEWKEYS
    debug1: SSH2_MSG_NEWKEYS received
    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/root/.ssh/id_rsa
    debug1: Server accepts key: pkalg ssh-rsa blen 279
    debug1: Authentication succeeded (publickey).
    Authenticated to bitbucket.org ([104.192.143.1]:22).
    debug1: channel 0: new [client-session]
    debug1: Entering interactive session.
    debug1: Sending environment.
    debug1: Sending env LANG = en_US.UTF-8
    PTY allocation request failed on channel 0
    authenticated via a deploy key.
    
    
    You can use git or hg to connect to Bitbucket. Shell access is disabled.
    
    This deploy key has read access to the following repositories:
    
    okchum/enbo: root@west -- root@west
    debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
    debug1: channel 0: free: client-session, nchannels 1
    Connection to bitbucket.org closed.
    Transferred: sent 3600, received 1872 bytes, in 3.6 seconds
    Bytes per second: sent 1003.6, received 521.9
    debug1: Exit status 0
    

    但是奇怪的是 MacBook 上用同样的 private key 克隆,没问题。看起来是服务器问题。 已经多次生成 key pairs ,将 public key 放到 bitbucket 了,没解决问题。 也试过 chmod 600 ~/.ssh/id_rsa

    ssh-add -l 也有这个 private key

    大家帮忙看下还有什么思路解决?

    谢谢大伙

    第 1 条附言  ·  2017-04-18 10:51:47 +08:00
    谢谢大家,解决啦,是用了其他用户,又不在 ~ 目录下, git clone 的时候提示权限不够,就加了 sudo ,没想到是系统权限的问题。在 ~ 目录下一切正常。也怪自己,在上边的日志把用户名替换成 root 了~
    7 条回复    2017-04-18 10:16:12 +08:00
    SoloCompany
        1
    SoloCompany  
       2017-04-17 23:16:22 +08:00   ❤️ 1
    先升级一下你本地的 ssh 吧
    sagaxu
        2
    sagaxu  
       2017-04-17 23:32:45 +08:00   ❤️ 1
    用 sudo 了?
    msg7086
        3
    msg7086  
       2017-04-18 01:24:59 +08:00   ❤️ 1
    /home/root/.ssh/id_rsa

    会不会和这个奇怪的路径有关?
    Valyrian
        4
    Valyrian  
       2017-04-18 01:38:59 +08:00   ❤️ 1
    可以试试 ssh -A
    DravenJohnson
        5
    DravenJohnson  
       2017-04-18 04:42:08 +08:00   ❤️ 1
    `chmod 400 ~/.ssh/id_rsa`
    DravenJohnson
        6
    DravenJohnson  
       2017-04-18 04:43:14 +08:00   ❤️ 1
    @DravenJohnson
    先确定你的 ~ 和 `/home/root/` 是一样的,如果服务器登陆用户不是 root 而且又用了 sudo 的话, key 的位置可能会不一样
    BOYPT
        7
    BOYPT  
       2017-04-18 10:16:12 +08:00   ❤️ 1
    似乎是在 git 里面跑了不一样的 ssh 命令,先看看~/.gitconfig 等全局配置看看有什么奇怪的东西不
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5272 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 03:46 · PVG 11:46 · LAX 19:46 · JFK 22:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.