【问题标题】:ANT SSHEXEC Password Prompt issues with su -csu -c 的 ANT SSHEXEC 密码提示问题
【发布时间】:2012-10-10 04:32:18
【问题描述】:

我试图绕过并发出 ANT / SSHEXEC 命令。

设置:

Solaris 服务器使用 NIS 和基于角色的用户进行运行时活动。

您不能直接登录到 RBAC 帐户,您必须以个人用户身份连接并且 su 连接到该用户 - 我已被告知在此环境中不能选择 SUDO。

所以我正在构建一些 ANT 脚本来构建、部署然后在远程服务器上运行一组脚本。

构建和部署很好,因为这是作为我的用户执行的,但是当尝试使用 SSHEXEC 连接到 su -c $user 时,我遇到了一个问题,shell 响应密码提示,但我无法输入任何东西。

所以在这里我要么想要一个解决方案,让我输入密码并继续,要么将密码作为我输入的变量传递给提示符。

这是我目前使用的代码:

<target name="install-products">
  <sshexec host="${remote.host1}" 
    username="${remote.user}" 
    password="${remote.pwd}"
    command="/usr/bin/su - $user -c cd ${remote.install.dir}/OracleSunJDK;./installJAVA.sh -p project -e 935"
    usepty="true"
    trust="true"
    failonerror="true"/>
</target>

所以我以我的用户身份连接,例如 ssh -t cambolie@${remote.host1}... 用户和密码如上所述传递,它的 su -c 然后导致提示出现。

这是目前发生的情况:

install-products:
[sshexec] Connecting to ${remote.host1}:22
[sshexec] cmd : /usr/bin/su - ${su-user}  -c cd /var/tmp/weblogic/RP_WEBLOGIC_J2EE_1.0.0.0/install/OracleSunJDK;./installJAVA.sh -p project -e 935
[sshexec] Password:

它只是在这个阶段挂起。

谁能帮忙?

【问题讨论】:

  • 在此处搜索 ssh 无密钥连接。这将需要一些工作并访问您的远程机器。祝你好运。
  • 不幸的是不是一个选项,因为我无法通过 SSH 直接连接到运行时用户,因此需要 su - ${su-user} -c。
  • 在 ant 1.8.4 上看到同样的问题。这不是连接问题,它可以使用私钥文件或用户/密码启动 ssh 会话。但是输入 su、sudo 等的“有用”似乎只是挂起
  • ant、java、jsch 的版本是什么?您可以尝试使用 Jsch => sourcefore.net/projects/jsch/files/jsch.jar 的最新版本 0.1.50 并设置 sshexec task='true' (default='false') 的详细属性以获得更多输出。
  • 错字,在这里获取 JSch 0.1.50 => sourceforge.net/projects/jsch/files/jsch.jar

标签: shell ant ssh automation build-automation


【解决方案1】:

以下是可能的解决方案之一。

  1. 将基于密钥的scp 从您的主机设置到您的目标计算机。
  2. 将构建脚本修改为 scp 标记文件(即 begin.install ,零字节文件)
  3. 在目标机器上设置一个 cron 来查找标记文件,一旦找到,就启动要在该服务器上执行的一组步骤。完成后,删除标记文件。

【讨论】:

    【解决方案2】:

    这对我有用:

       <property name="password" value="MYPASS"/>
    
        <!-- Keep the closing property tag on the new line as su needs the CR/LF-->
        <property name="password.crlf">${password}<!-- do not remove the CR/LF-->
        </property>
        <!-- Keep the closing property tag on the new line as su needs the CR/LF-->
    
      <sshexec host="${server}"
                     username="${username1}"
                     password="${password1}"
                     trust="yes"
                     verbose="yes"
                     usepty="true"
                     inputproperty="password.crlf"
                     command="su - otheruser -c ls"
            />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-05
      • 1970-01-01
      • 2020-12-18
      • 2020-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多