如何使用配置了密码短语的私钥来使用Ant的sshexec
任务?
我找到了以下解决方法:
-Dpass=mypass
(不安全)这些对我来说都不是一个好选择,但第一个是可以接受的。
在pageant
中加载私钥似乎根本没有帮助。从其他答案来看,似乎Ant试图访问它,但它不能,回到密码身份验证,但失败了:
com.jcraft.jsch.JSchException: Auth cancel
at com.jcraft.jsch.Session.connect(Session.java:490)
at com.jcraft.jsch.Session.connect(Session.java:162)
... (rest of the stack trace omitted)
另一个常见症状是未安装Unlimited Strength JCE时,错误类似于:
com.jcraft.jsch.JSchException: The cipher 'aes256-cbc' is required, but it is not available.
at com.jcraft.jsch.KeyPair.loadPPK(KeyPair.java:942)
at com.jcraft.jsch.KeyPair.load(KeyPair.java:515)
... (rest of the stack trace omitted)
回到我的问题,如何使这项工作正常?使用带密码的私钥,无需在任何地方硬编码或进入命令行?最好使用pageant
,我可以输入密码并在运行Ant任务之前存储私钥。
答案 0 :(得分:1)
如果你从命令行运行你的ant文件,你可能会要求你输入密码而不是硬编码。重要的部分是提示输入密码,将其存储在属性中并在passphrase-argument中引用此属性。
<target name="copy">
<input message="Enter passphrase for keyfile:" addproperty="the.password">
<handler classname="org.apache.tools.ant.input.SecureInputHandler" />
</input>
<upload-files host="the.host" />
</target>
<macrodef name="upload-files">
<attribute name="host" />
<sequential>
<scp file="${the.file}"
todir="@{host}:directoryname/${filename}"
keyfile="${key.file}" passphrase="${the.password}" verbose="true"/>
</sequential>
</macrodef>
要求:
来源:http://www.dcepler.net/post.cfm/hiding-password-input-in-ant