首页 > 解决方案 > 使用 ProxyCommand 和 Gateway 通过 SSH 从 bitbucket 管道部署到服务器

问题描述

我有一个与我的计算机完美配合的部署过程,我想在 bitbucket 管道中使用它。

SSH 配置文件定义了连接:

Host my-host
    User my-user
    Hostname my-host-name
    IdentityFile ~/.ssh/id_rsa
    ProxyCommand ssh -v -i ~/.ssh/id_rsa -W %h:%p my-user@my-gateway.com

id_rsa.pub在两个.ssh/authorized_keys文件中。

SSH 连接就像一个魅力。

我为 bitbucket 管道生成了一个 SSH 密钥对并将其放入相同的.ssh/authorized_keys.

这是我测试 ssh 连接的管道:

image: node:8.11.2    
pipelines:
  branches:
    stage/development:
      - step:
          caches:
            - node
          script:
          - mkdir -p ~/.ssh
          - (umask  077 ; echo $DEV_PIPELINE_KEY | base64 --decode > ~/.ssh/id_rsa)
          - cat bitbucket-ssh-config >> ~/.ssh/config
          - ssh my-host

代表我存储在 bitbucket 中的$DEV_PIPELINE_KEY私钥。该bitbucket-ssh-config文件与上述文件相同。

它在网关 ssh 连接中成功,但随后失败,我不明白为什么。以下是日志:

不会分配伪终端,因为 stdin 不是终端。

OpenSSH_6.7p1 Debian-5+deb8u4,OpenSSL 1.0.1t 2016 年 5 月 3 日

debug1:读取配置数据 /root/.ssh/config

debug1:读取配置数据 /etc/ssh/ssh_config

debug1:/etc/ssh/ssh_config 第 19 行:为 * 应用选项

debug1:连接到 GATEWAY_HOST.com [GATEWAY_IP] 端口 22。

debug1:建立连接。

调试1:永久设置uid:0/0

debug1:key_load_public:没有这样的文件或目录

debug1:身份文件 /root/.ssh/id_rsa 类型 -1

debug1:key_load_public:没有这样的文件或目录

debug1:身份文件/root/.ssh/id_rsa-cert type -1

debug1:key_load_public:没有这样的文件或目录

debug1:身份文件/opt/atlassian/pipelines/agent/ssh/id_rsa type -1

debug1:key_load_public:没有这样的文件或目录

debug1:身份文件/opt/atlassian/pipelines/agent/ssh/id_rsa-cert type -1

debug1:为协议 2.0 启用兼容模式

debug1:本地版本字符串 SSH-2.0-OpenSSH_6.7p1 Debian-5+deb8u4

debug1:远程协议版本2.0,远程软件版本OpenSSH_7.2p2 Ubuntu-4ubuntu2.4

debug1:匹配:OpenSSH_7.2p2 Ubuntu-4ubuntu2.4 pat OpenSSH* compat 0x04000000

debug1: SSH2_MSG_KEXINIT 已发送

debug1:收到 SSH2_MSG_KEXINIT

debug1: kex: server->client aes128-ctr umac-64-etm@openssh.com 无

debug1:kex:客户端->服务器 aes128-ctr umac-64-etm@openssh.com 无

debug1:发送 SSH2_MSG_KEX_ECDH_INIT

debug1:期待 SSH2_MSG_KEX_ECDH_REPLY

debug1:服务器主机密钥:RSA GATEWAY_FINGERPRINT

debug1:主机 'GATEWAY_HOST.com' 已知并且与 RSA 主机密钥匹配。

debug1:在 /root/.ssh/known_hosts:3 中找到密钥

警告:将 IP 地址“GATEWAY_IP”的 RSA 主机密钥永久添加到已知主机列表中。

debug1: SSH2_MSG_NEWKEYS 已发送

debug1:期待 SSH2_MSG_NEWKEYS

debug1:收到 SSH2_MSG_NEWKEYS

debug1:SSH2_MSG_SERVICE_REQUEST 已发送

debug1:收到 SSH2_MSG_SERVICE_ACCEPT

debug1:可以继续的身份验证:publickey

debug1:下一个认证方式:publickey

debug1:尝试私钥:/root/.ssh/id_rsa

debug1:认证成功(公钥)。

已通过 GATEWAY_HOST.com ([GATEWAY_IP]:22) 的身份验证。

debug1:channel_connect_stdio_fwd 我的主机:22

debug1:通道 0:新的 [stdio-forward]

debug1:getpeername 失败:错误的文件描述符

debug1:请求 no-more-sessions@openssh.com

debug1:进入交互式会话。

调试1:client_input_global_request:rtype hostkeys-00@openssh.com want_reply 0

      Host key verification failed.

debug1:通道 0:空闲:direct-tcpip:监听端口 0 用于我的主机端口 22,从 127.0.0.1 端口 65535 连接到 UNKNOWN 端口 65536,nchannels 1

debug1: fd 0 清除 O_NONBLOCK

debug1: fd 1 清除 O_NONBLOCK

debug1:被信号 1 杀死。

标签: gitsshbitbucket-pipelines

解决方案


推荐阅读