我一直试图获得一个从Drone运行的SSH命令,这个命令运行在一个名为bb
的Docker容器中。 我已经在我的Dockerfile中添加了RUN echo " IdentityFile /root/.ssh/id_rsa" >> /etc/ssh/ssh_config
。
我已经使用docker run -it bb /bin/bash
来检查SSH密钥是否存在,并且可以使用该交互式terminal成功将SSH SSH连入远程主机。
但是,当我尝试使用如下所示的.drone.yml
构build脚本执行相同的命令时:
image: bb script: - whoami - ssh -vvv -t -t 192.0.2.1 "whoami"
…被禁止使用基于密码的身份validation后,我得到“权限被拒绝”的错误。 ( 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
),我可以看到我的成功testing,但是当Drone运行它的容器时,日志报告“RSA_public_decrypt失败”。 这里是日志。
成功(交互容器)login:
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
失败(无人机容器)login:
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]
所以它看起来像我的密钥不是由无人机容器发送。 我已经在构build脚本中运行了whoami
,并且报告它以root
身份运行,这正是我所期望的。
我怎样才能使这个工作?
得到它了。 在挖掘该存储库的设置时,我注意到了一个“公钥”字段:
我尝试将其添加到authorized_keys
文件,并运行我的.drone.yml
,你知道什么 – 它的工作。 回去检查文件 – 这是无处可查。 无证超级秘密领域FTW。