詹金斯-能不能;执行Shell";执行SSH命令

詹金斯-能不能;执行Shell";执行SSH命令,ssh,jenkins,Ssh,Jenkins,Jenkins的“executeshell”是否可以执行SSH命令 Jenkins有许多构建前和构建后选项,专门针对SSH类型的命令,但是我有一个脚本,它同时构建SCP和SSH命令。Jenkins是否在强迫用户将构建脚本分解为多个步骤 “executeshell”是我试图从中执行SSH命令的Shell,但没有成功 debug1: Authentications that can continue: publickey,password debug1: Next authentication me

Jenkins的“executeshell”是否可以执行SSH命令

Jenkins有许多构建前和构建后选项,专门针对SSH类型的命令,但是我有一个脚本,它同时构建SCP和SSH命令。Jenkins是否在强迫用户将构建脚本分解为多个步骤

“executeshell”是我试图从中执行SSH命令的Shell,但没有成功

debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /var/lib/jenkins/.ssh/identity
debug1: Trying private key: /var/lib/jenkins/.ssh/id_rsa
debug1: Trying private key: /var/lib/jenkins/.ssh/id_dsa
debug1: Next authentication method: password
debug1: read_passphrase: can't open /dev/tty: No such device or address
debug1: Authentications that can continue: publickey,password
Permission denied, please try again.
debug1: read_passphrase: can't open /dev/tty: No such device or address
debug1: Authentications that can continue: publickey,password
Permission denied, please try again.
debug1: read_passphrase: can't open /dev/tty: No such device or address
debug1: Authentications that can continue: publickey,password
debug1: No more authentication methods to try.
Permission denied (publickey,password).
SSH Access not available for build engine

只要使用公钥,就可以通过
ssh
发送命令,并通过
scp
复制文件。我们使用它来产生一些特定的进程,并发布某些由于各种原因无法通过现有命令推送的工件

在远程服务器上使用哪些密钥以及对哪些用户进行寻址时,必须小心。通常,我们在ssh中使用显式的
-i
参数,并且总是使用显式的用户名来确保一切按预期进行

ssh -i <key_path> <user>@<fqdn_host> <command>
ssh-i@
如果你在脚本中这样做,你应该很好。当然,Jenkins进程必须能够读取密钥文件,并且需要确保密钥安装在两侧

我还强烈建议使用ssh的内置策略控件来控制:

  • 哪些主机可以使用此密钥
  • 此键可以使用哪些命令
特别是,您可以在作为ssh/scp命令目标的主机上使用
~/.ssh/authorized_keys
中的设置来限制可以连接的主机(
host=
),甚至可以预加载该命令,以便特定密钥始终只执行一个特定命令(
command=


对于真正的冒险,您可以指定一个
命令=
并将命令发送到限制目录访问或命令访问的受限shell命令。

您可以使用一个现有的Jenkins加载项,而不是从“Execute shell”步骤显式执行
ssh
命令:

  • -执行SSH命令或通过SCP/SFTP传输文件
  • -执行SSH命令