gpt4 book ai didi

ssh - Jenkins - "Execute Shell"能否执行 SSH 命令

转载 作者:行者123 更新时间:2023-12-02 13:46:37 25 4
gpt4 key购买 nike

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

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

“执行 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 发送命令。并通过 scp 复制文件.我们使用它来生成一些特定的进程并发布某些由于各种原因无法通过现有命令推送的工件。

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

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

如果您在脚本中执行此操作,则应该没问题。当然,您的 Jenkins 进程必须可以读取 key 文件,并且您需要确保 key 安装在两侧。

我还强烈建议使用 ssh 的内置策略控制来控制:
  • 哪些主机可以使用此 key
  • 这个键可以使用什么命令

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

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

    关于ssh - Jenkins - "Execute Shell"能否执行 SSH 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18227009/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com