首页 > 解决方案 > SSH 文件复制 - 不允许使用公钥

问题描述

获得了我们自己的 Linux 服务器构建/发布池。我在管道中有一项任务,通过 ssh 将文件复制到远程服务器。

在构建服务器上,作为代理运行的服务帐户用户,我运行ssh-keygen. 点击进入所有问题。

我将构建代理.ssh/id_rsa.pub文件复制到.ssh/authorized_keys远程服务器上。

我确保在远程服务器上相应地设置了权限(仅限用户 rw)。

在构建服务器上,作为构建代理我运行:

ssh user@remoteserver

而且我没有密码就登录了。惊人的!密钥交换工作!

然后,我在 Azure DevOps 和“通过 SSH 复制文件”任务中创建一个服务连接,指定要使用的远程用户的服务连接,并提供远程服务器用户的私钥。

管道失败:

2019-08-09T21:15:05.7510316Z ##[error]Error: Failed to connect to remote machine. Verify the SSH service connection details. Failed to connect to remote machine. Verify the SSH service connection details. Error: All configured authentication methods failed..`

我在远程服务器上启用DEBUG3模式并在日志中看到此消息:

Aug  9 15:16:54 vwc1uewbapp52 sshd[63105]: debug3: mm_answer_keyallowed entering
Aug  9 15:16:54 vwc1uewbapp52 sshd[63105]: debug3: mm_answer_keyallowed: key_from_blob: 0x560ecb33c5f0
Aug  9 15:16:54 vwc1uewbapp52 sshd[63105]: debug1: temporarily_use_uid: 52139/52139 (e=0/0)
Aug  9 15:16:54 vwc1uewbapp52 sshd[63105]: debug1: trying public key file /home/buildagent/.ssh/authorized_keys
Aug  9 15:16:54 vwc1uewbapp52 sshd[63105]: debug1: fd 9 clearing O_NONBLOCK
Aug  9 15:16:54 vwc1uewbapp52 sshd[63105]: debug2: key not found
Aug  9 15:16:54 vwc1uewbapp52 sshd[63105]: debug1: restore_uid: 0/0
Aug  9 15:16:54 vwc1uewbapp52 sshd[63105]: debug3: mm_answer_keyallowed: key 0x560ecb33c5f0 is not allowed
Aug  9 15:16:54 vwc1uewbapp52 sshd[63105]: Failed publickey for buildagent from 10.251.80.6 port 57726 ssh2: RSA SHA256:PTyAT4hagIZCh2QM8lDvOneF0BIlu6wCiGdfH/Ro5no
Aug  9 15:16:54 vwc1uewbapp52 sshd[63105]: debug3: mm_request_send entering: type 23
Aug  9 15:16:54 vwc1uewbapp52 sshd[63105]: debug2: userauth_pubkey: authenticated 0 pkalg ssh-rsa [preauth]
Aug  9 15:16:54 vwc1uewbapp52 sshd[63105]: debug3: userauth_finish: failure partial=0 next methods="publickey,gssapi-keyex,gssapi-with-mic,password" [preauth]

为什么它可以手动工作,使用相同的用户,而不是作为管道运行时?

标签: azure-devops

解决方案


推荐阅读