如何使用ant sshexec执行sudo命令

3
我正在尝试在远程服务器上使用sudo执行命令,类似于这样:
<target name="remote-test">
    <sshexec host="${remote.host}"
        username="${remote.user}"
        password="${remote.pass}"
        trust="true"
        usepty="true"
        command="sudo ls /home/myuser" />
</target>

但服务器响应如下:
Buildfile: build.xml
remote-test:
  [sshexec] Connecting to 0.0.0.0:22
  [sshexec] cmd : sudo ls /home/myuser
  [sshexec] [sudo] password for myuser:

那么,我该如何使用Ant执行具有sudo权限的远程命令呢?
谢谢 :)

可能是Passing a password to "su" command over sshexec from ant的重复问题。 - Mark O'Connor
1个回答

4

是的,也许可以像这样复制:

如何在不覆盖TTY的情况下将密码传递给su/sudo/ssh?

但无论如何,解决此问题的一种方法就像最受欢迎的答案中所说的那样。

<target name="remote-test-jboss">
    <sshexec host="${remote.host}"
        username="${remote.user}"
        password="${remote.pass}"
        command="echo ${remote.pass}| sudo -S ls /home/myserver" 
        trust="true"
    />
</target>

-S参数用于从标准输入读取。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接