【问题标题】:Jenkins Can execute shell script on remote host using ssh support socks4 proxy?Jenkins 可以使用 ssh 支持 socks4 代理在远程主机上执行 shell 脚本吗?
【发布时间】:2018-12-11 03:20:05
【问题描述】:

出于某种原因,公司需要在 socks 代理后面的服务器上自动执行几个命令。 到目前为止,我以这种方式在管道中做到了这一点(尽管这对我来说是很新的):

sh 'ssh -vvv -t -o StrictHostKeyChecking=no -o ProxyCommand="nc -x elki-palki.socks4.chot-b-ego.com:1080 %h %p" petya.properdikin@xxx.xxx.xxx.xxx

有没有办法使用 SOCKS4 代理配置 SSH 站点以使用通常的 Freestyle Jobs? enter image description here

【问题讨论】:

    标签: jenkins proxy jenkins-pipeline socks


    【解决方案1】:

    已解决,只是拒绝在远程主机上使用 ssh 执行 shell 脚本。而是使用普通的执行 shell。然后你必须在 ~/.ssh/config 或全局 /etc/ssh/ssh_config 中创建 ssh_config 并在此处使用 Socks4(或使用的任何代理)粘贴信息:

    Host xxx.xxx.xxx.xxx
        ProxyCommand='nc -x elki-palki.socks.chob-ego.com:1080 %h %p'
        User petya.properdikin
        ForwardAgent yes
        Port 22
    

    那么它应该可以工作(假设 ssh 密钥设置正确)

    【讨论】:

      【解决方案2】:

      this question 中对管道中的 ssh 进行了很好的解释

      对于 socks 代理,它更复杂。 基于this articleJava docs,您必须使用一些额外的标志来启动您的Jenkins,这里是文档:

      袜子 这是另一种类型的代理。它允许较低级别的类型 隧道,因为它在 TCP 级别工作。实际上,在 Java(tm) 平台设置 SOCKS 代理服务器将导致所有 TCP 连接通过该代理,除非其他代理 指定的。如果 Java SE 实现支持 SOCKS,则 将使用以下属性:

      socksProxyHost (default: <none>)
      The hostname, or address, of the proxy server.
      
      socksProxyPort (default: 1080)
      The port number of the proxy server.
      
      socksProxyVersion (default: 5)
      The version of the SOCKS protocol supported by the server. The default is 5 indicating SOCKS V5, alternatively 4 can be specified for
      

      袜子 V4。将属性设置为这些以外的值会导致 未指定的行为。

      java.net.socks.username (default: <none>)
      Username to use if the SOCKSv5 server asks for authentication and no java.net.Authenticator instance was found.
      
      java.net.socks.password (default: <none>)
      Password to use if the SOCKSv5 server asks for authentication and no java.net.Authenticator instance was found.
      

      它很可能看起来像这样

      java -DsocksProxyHost=some.proxy.host -DsocksProxyPort=1234 -DsocksProxyVersion=4 -jar jenkins.war
      

      取决于您实际启动 jenkins 等的方式。

      【讨论】:

      • 好吧,问题是关于如何在通常的 Freestyle Jobs 中使用 Socks4 代理(如果有任何方法可以做到这一点)(例如“使用 ssh 在远程主机上执行 shell 脚本”步骤 - 见附件截图在第 1 篇文章中)而不是在管道或如何在 Socks4 代理服务器后面使用 Jenkins 服务器。
      猜你喜欢
      • 1970-01-01
      • 2014-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 2013-10-16
      • 1970-01-01
      相关资源
      最近更新 更多