首页 > 解决方案 > Travis CI 无法与 publickey 进行 rsync (ssh),但相同的命令在终端中有效

问题描述

我正在使用 TRAVIS CI 设置自动部署,但我的脚本在尝试 rsync 到我的服务器时卡住了。据我所知,失败的是SSH登录,特别是公钥登录。

我的 YAML 文件(User,HostDir( Key Decryptionopenssl aes--256-cbc etc...) 已替换):

language: node_js 
node_js:
- 10.7.0 
addons:
  ssh_known_hosts: <HOST>   
  hosts: <HOST> 
branches:   
  only:
  - master 
env:   
  global:
  - DEPLOY_USER=<USER>
  - DEPLOY_HOST=<HOST>
  - DEPLOY_DIRECTORY=<DIR> 
before_install:
- npm install -g npm@6.4.1 
install:
- npm install 
script:
- npm run build 
before_deploy:
- <DECRYPTION> -in deploy_rsa.enc -out /tmp/deploy_rsa -d
- eval "$(ssh-agent -s)"
- chmod 600 /tmp/deploy_rsa
- ssh-add /tmp/deploy_rsa 
deploy:   
  provider: script   
  skip_cleanup: true   
  script: rsync -r --delete-after --quiet -e"ssh -v -i /tmp/deploy_rsa" $TRAVIS_BUILD_DIR/dist/ <USER>@<HOST>:<DIR>   
on:
  branch: master

一切正常,直到 rsync,它给出了这个日志(这里再次替换了主机名、用户和 ECDSA 密钥):

Deploying application
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /home/travis/.ssh/config
debug1: /home/travis/.ssh/config line 1: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to <HOST> [127.0.0.1] port 22.
debug1: Connection established.
debug1: identity file /tmp/deploy_rsa type -1
debug1: identity file /tmp/deploy_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8 pat OpenSSH_6.6.1* compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA <ECDSA>
debug1: Host '<HOST>' is known and matches the ECDSA host key.
debug1: Found key in /home/travis/.ssh/known_hosts:11
debug1: ssh_ecdsa_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,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /tmp/deploy_rsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /tmp/deploy_rsa
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type RSA
<USER>@<HOST>'s password: debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: password

当我在自己的机器上尝试相同的 rsync 命令时(使用相同的公钥和测试文件夹),它可以工作并给出:

debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: deploy_rsa
debug1: Authentication succeeded (publickey).
Authenticated to <HOST>.

我已经搜索了文档,进行了广泛的搜索,已经尝试了很多不同的东西,将密钥添加到 ssh-agent 的不同方法,手动指定它,sudo true/false/required 等等......我是不知所措。

我注意到日志的细微差别,TRAVIS 日志似乎认为我的服务器接受密码身份验证,而我自己机器的日志仅显示“publickey”作为有效方法,这是正确的,因为密码身份验证被禁用。

ssh-agent 正确尝试在 /tmp/deploy_rsa 中提供密钥,但由于某种原因失败,然后我手动提供它,它显示key_parse_private2: missing begin marker(从我的搜索来看,这似乎是一条正常消息,表明无密码登录成功?)并且似乎再次失败。

有没有办法让 TRAVIS 明白密码登录被禁用?强制 ssh-agent 只使用 publickey ?为什么它看似重试(尝试来自 ssh-agent 的密钥,尝试我的密钥等)但没有显示任何失败消息,密钥似乎已识别且有效。

可能解密的密钥(deploy_rsa)无效?相同的密钥,然后travis encrypt-file deploy_rsa --add在我的机器上使用作品进行加密。

预先感谢您的回答。

标签: sshyamltravis-cirsyncssh-keys

解决方案


好吧,事实证明 Travis CI 不想要域名(即使这对我来说适用于所有其他情况),并且绝对需要 IP 地址。

我试过了,但有其他早期的问题(解密私钥),一旦这些问题得到修复,就忘了尝试 IP。

我觉得很傻,但现在可以了。


推荐阅读