【问题标题】:Jenkins - can the "Execute Shell" execute SSH commandsJenkins - “执行外壳”可以执行 SSH 命令吗
【发布时间】:2013-08-16 03:02:34
【问题描述】:

Jenkins“Execute shell”是否可以执行 SSH 命令?

Jenkins 有许多专门针对 SSH 类型命令的构建前和构建后选项,但是我有一个脚本,它既可以构建,也可以执行 SCP 和 SSH 命令。 Jenkins 是否强制用户将构建脚本分解为多个步骤?

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

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 jenkins


    【解决方案1】:

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

    有必要注意您使用的密钥以及您在远程服务器上寻址的用户。通常,我们在 ssh 中使用显式的 -i 参数,并且我们总是使用显式的用户名来确保一切都按预期进行

    ssh -i <key_path> <user>@<fqdn_host> <command>
    

    如果您在脚本中执行此操作,应该没问题。当然,您的 Jenkins 进程必须能够读取密钥文件,并且您需要确保在双方都安装了密钥。

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

    • 哪些主机可以使用此密钥
    • 此键可以使用哪些命令

    特别是,您可以在作为 ssh/scp 命令目标的主机上使用 ~/.ssh/authorized_keys 中的设置来限制可以连接的主机 (host=),甚至可以预加载命令,以便特定key 总是只执行一个特定的命令 (command=)。

    对于真正喜欢冒险的人,您可以指定 command= 并将命令发送到受限制的 shell 命令,从而限制目录访问或命令访问。

    【讨论】:

      【解决方案2】:

      您可以使用现有的 Jenkins 插件之一,而不是从“执行 shell”步骤显式执行 ssh 命令:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-08
        • 2016-10-10
        • 1970-01-01
        • 2014-12-03
        • 1970-01-01
        相关资源
        最近更新 更多