ant - 输入 sshexec 的密码 [英] ant - input password for sshexec

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

问题描述

我在公共服务器上有一个可供多个用户使用的 ant 脚本.我想安全地将密码输入脚本并将其用于多个目标.以下代码通过输入获取密码,但未将变量传递给 sshexec 任务.

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>

推荐答案

好的...我知道我迟到了一年,但对于新来的人,这就是我解决问题的方式.我的目标是以 root 身份执行命令而不泄露我的密码(显然)

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>

最后,我在服务器的 ~/become-root.sh 中创建了一个 bash 脚本,如下所示

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 --

如果您调用 execute-command 任务,您现在可以以 sudo 身份运行命令(假设您的用户是 sudoer)

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

希望这会有所帮助!

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

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