蚂蚁 - 为sshexec输入密码 [英] ant - input password for sshexec

查看:158
本文介绍了蚂蚁 - 为sshexec输入密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有可供多个用户在公共服务器上的蚂蚁脚本。我想输入一个密码,安全的脚本,并将其用于多个目标。下面code得到与输入密码,但是变量没有被传递到sshexec任务。

将这项工作还是有更好的方式来做到这一点?

 <目标名称=get_password>
        <输入消息=输入您的密码:>方法addProperty =密码>
                <处理器类名=org.apache.tools.ant.input.SecureInputHandler/>
        < /输入>
< /目标与GT;<目标名称=create_tmp_dir>
        < sshexec主机=$ {HOST}
        用户名=$ {用户名}
        密码=$ {}密码
        命令=的mkdir $ {} TMP_DIR/>
< /目标与GT;


解决方案

好吧......我看到,我晚了一年,但对于新加入者这是我解决了这个问题。
我的目标是不透露我的密码(显然)

执行命令根

 <目标名称=getServerCredentials除非=$ {} server.user>
    <输入消息=$ {服务器名称}用户:方法addProperty =server.user/>
    <输入消息=$ {} server.user密码的方法addProperty =server.pass>
        <处理器类名=org.apache.tools.ant.input.SecureInputHandler/>
    < /输入>
< /目标与GT;
<目标名称=执行命令取决于=getServerCredentials>
    < sshexec主机=$ {服务器名}用户名=$ {} server.user密码=$ {} server.pass命令= inputproperty =服务器〜/ become-root.sh。通过/>
< /目标与GT;

最后,我已经在我的服务器,它看起来像这样创造了一个bash脚本在〜/ become-root.sh

 #!/ bin / sh的
阅读VAR
回声是$ var |须藤-S WHOAMI -

如果你调用执行命令,你现在可以运行和sudo的命令任务(假设你的用户是sudoer)

希望这有助于!

I have an ant script on a public server available to multiple users. I want to input a password into a script securely and use it for multiple targets. The following code gets a password with input, but the variable is not being passed to the sshexec task.

Will this work or is there a better way to do it?

<target name="get_password">
        <input message="Enter Your Password:>" addproperty="password">
                <handler classname="org.apache.tools.ant.input.SecureInputHandler" />
        </input>
</target>

<target name="create_tmp_dir">
        <sshexec host="${host}"
        username="${username}"
        password="${password}"
        command="mkdir ${tmp_dir}" />
</target>

解决方案

Ok...I see that I am a year late but for new comers this is how I solved the problem. My goal was to execute a command as root without revealing my password (obviously)

<target name="getServerCredentials" unless="${server.user}">
    <input message="${server-name} user:" addproperty="server.user" />
    <input message="${server.user} password:" addproperty="server.pass">
        <handler classname="org.apache.tools.ant.input.SecureInputHandler" />
    </input>
</target>


<target name="execute-command" depends="getServerCredentials">
    <sshexec host="${server-name}" username="${server.user}" password="${server.pass}" command="~./become-root.sh" inputproperty="server.pass"/>
</target>

Finally I've created a bash script in ~/become-root.sh in my server that looked like this

#!/bin/sh
read var
echo $var | sudo -S whoami --

If you call execute-command task you can now run commands as sudo (assuming that your user is sudoer)

Hope this helps!

这篇关于蚂蚁 - 为sshexec输入密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆