使用Drone从Docker镜像SSH

时间:2015-12-06 23:00:38

标签: linux ssh docker drone

我已经尝试了很长时间才能从Drone中获取SSH命令,该命令在名为bb的Docker容器中运行。根据其他线程中的一些建议,我在我的Dockerfile中添加了RUN echo " IdentityFile /root/.ssh/id_rsa" >> /etc/ssh/ssh_config

我已使用docker run -it bb /bin/bash检查SSH密钥是否存在,并且我可以使用该交互式终端成功SSH到远程主机。

但是,当我尝试使用.drone.yml构建脚本执行相同的命令时:

image: bb
script:
  - whoami
  - ssh -vvv -t -t 192.0.2.1 "whoami"

......我得到了#34;许可被拒绝"被归结为基于密码的识别后的错误。 (whoami在容器内运行,输出root,然后继续ssh命令。)

我已将详细输出归结为相关部分:

debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /root/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug2: input_userauth_pk_ok: fp f2:...
debug3: sign_and_send_pubkey: RSA f2:...
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: publickey,password
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password

...它明确说明"我们没有发送数据包,禁用方法"。我已使用ssh-keygen -lf /root/.ssh/id_rsa检查了密钥的指纹,并且它与输出中的指纹匹配。

然后我在远程主机上观看了auth日志(/var/log/auth.log)并且我可以看到我的成功测试,但是当Drone运行其容器时,日志报告“RSA_public_decrypt失败了”#39;这是日志。

成功(交互式容器)登录:

Accepted publickey for root from 192.0.2.1 port 59472 ssh2: RSA f2:...
pam_unix(sshd:session): session opened for user root by (uid=0)
Received disconnect from 192.0.2.1: 11: disconnected by user
pam_unix(sshd:session): session closed for user root

失败(无人机容器)登录:

error: RSA_public_decrypt failed: error:04067084:lib(4):func(103):reason(132)
Failed password for root from 192.0.2.1 port 54172 ssh2
Failed password for root from 192.0.2.1 port 54172 ssh2
Connection closed by 192.0.2.1 [preauth]

因此看起来我的密钥不是由Drone容器发送的。我已在构建脚本中运行whoami,并报告它以root运行,这正是我所期望的。

我怎样才能让它发挥作用?

1 个答案:

答案 0 :(得分:2)

GOT IT。在挖掘该存储库的设置时,我注意到了一个“公钥”字段:

enter image description here

我尝试将其添加到authorized_keys文件,并运行我的.drone.yml,你知道什么 - 它有效。回去检查文档 - 它无处可寻。无证超级秘密领域FTW。