You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

sshexec.html 10 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <!DOCTYPE html>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. https://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <html lang="en">
  17. <head>
  18. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  19. <title>SSHEXEC Task</title>
  20. </head>
  21. <body>
  22. <h2 id="sshexec">SSHEXEC</h2>
  23. <p><em>Since Apache Ant 1.6</em></p>
  24. <h3>Description</h3>
  25. <p>Runs a command on a remote machine running SSH daemon.</p>
  26. <p><strong>Note</strong>: This task depends on external libraries not included in the Ant
  27. distribution. See <a href="../install.html#librarydependencies">Library Dependencies</a> for more
  28. information. This task has been tested with JSCh 0.1.29 and above and won't work with versions of
  29. JSCh earlier than 0.1.28.</p>
  30. <p>See also the <a href="scp.html">scp task</a></p>
  31. <h3>Parameters</h3>
  32. <table class="attr">
  33. <tr>
  34. <th scope="col">Attribute</th>
  35. <th scope="col">Description</th>
  36. <th scope="col">Required</th>
  37. </tr>
  38. <tr>
  39. <td>host</td>
  40. <td>The hostname or IP address of the remote host to which you wish to connect.</td>
  41. <td>Yes</td>
  42. </tr>
  43. <tr>
  44. <td>username</td>
  45. <td>The username on the remote host to which you are connecting.</td>
  46. <td>Yes</td>
  47. </tr>
  48. <tr>
  49. <td>command</td>
  50. <td>The command to run on the remote host.</td>
  51. <td rowspan="2">Exactly one of the two</td>
  52. </tr>
  53. <tr>
  54. <td>commandResource</td>
  55. <td class="left">The resource (file) that contains the commands to run on the remote
  56. host. <em>Since Ant 1.7.1</em></td>
  57. </tr>
  58. <tr>
  59. <td>port</td>
  60. <td>The port to connect to on the remote host.</td>
  61. <td>No; defaults to <q>22</q></td>
  62. </tr>
  63. <tr>
  64. <td>trust</td>
  65. <td>This trusts all unknown hosts if set to <q>yes</q>
  66. or <q>true</q>.<br/><strong>Note</strong>: If you set this to <q>false</q> (the default), the
  67. host you connect to must be listed in your <var>knownhosts</var> file, this also implies that
  68. the file exists.</td>
  69. <td>No; defaults to <q>no</q></td>
  70. </tr>
  71. <tr>
  72. <td>knownhosts</td>
  73. <td>This sets the known hosts file to use to validate the identity of the remote host. This
  74. must be a SSH2 format file. SSH1 format is not supported.</td>
  75. <td>No; defaults to <q>${user.home}/.ssh/known_hosts</q></td>
  76. </tr>
  77. <tr>
  78. <td>failonerror</td>
  79. <td>Whether to halt the build if the command does not complete successfully.</td>
  80. <td>No; defaults to <q>true</q></td>
  81. </tr>
  82. <tr>
  83. <td>password</td>
  84. <td>The password.</td>
  85. <td>Yes, unless you are using key based authentication or the password has been given in the
  86. file or <var>todir</var> attribute.</td>
  87. </tr>
  88. <tr>
  89. <td>keyfile</td>
  90. <td>Location of the file holding the private key.</td>
  91. <td>Yes, if you are using key based authentication</td>
  92. </tr>
  93. <tr>
  94. <td>passphrase</td>
  95. <td>Passphrase for your private key.</td>
  96. <td>No; defaults to an empty string</td>
  97. </tr>
  98. <tr>
  99. <td>suppresssystemout</td>
  100. <td>Whether to suppress system out. <em>since Ant 1.9.0</em></td>
  101. <td>No; defaults to <q>false</q></td>
  102. </tr>
  103. <tr>
  104. <td>suppresssystemerr</td>
  105. <td>Whether to suppress <code>System.err</code>. <em>since Ant 1.9.4</em></td>
  106. <td>No; defaults to <q>false</q></td>
  107. </tr>
  108. <tr>
  109. <td>output</td>
  110. <td>Name of a file to which to write the output.</td>
  111. <td>No</td>
  112. </tr>
  113. <tr>
  114. <td>errorOutput</td>
  115. <td>The file to which the standard error of the command should be redirected. <em>since Ant
  116. 1.9.4</em></td>
  117. <td>No</td>
  118. </tr>
  119. <tr>
  120. <td>append</td>
  121. <td>Whether <var>output</var> file should be appended to or overwritten.</td>
  122. <td>No; defaults to <q>false</q>, meaning overwrite any existing file</td>
  123. </tr>
  124. <tr>
  125. <td>errAppend</td>
  126. <td>Whether <var>errorOutput</var> file should be appended to or overwritten. <em>since Ant
  127. 1.9.4</em></td>
  128. <td>No; defaults to <q>false</q>, meaning overwrite any existing file</td>
  129. </tr>
  130. <tr>
  131. <td>outputproperty</td>
  132. <td>The name of a property in which the output of the command should be stored. If you use
  133. the <var>commandResource</var> attribute, each command's output will be prefixed by the
  134. command itself.</td>
  135. <td>No</td>
  136. </tr>
  137. <tr>
  138. <td>errorproperty</td>
  139. <td>The name of a property in which the standard error of the command should be
  140. stored. <em>since Ant 1.9.4</em></td>
  141. <td>No</td>
  142. </tr>
  143. <tr>
  144. <td>resultproperty</td>
  145. <td>the name of a property in which the return code of the command should be stored. Only of
  146. interest if <var>failonerror</var>=<q>false</q>. <em>since Ant 1.9.4</em></td>
  147. <td>No</td>
  148. </tr>
  149. <tr>
  150. <td>timeout</td>
  151. <td>Stop the command if it doesn't finish within the specified time (given in
  152. milliseconds <strong>unlike <code>telnet</code>, which expects a timeout in
  153. seconds</strong>).</td>
  154. <td>No; defaults to <q>0</q> which means <q>never</q></td>
  155. </tr>
  156. <tr>
  157. <td>input</td>
  158. <td>A file from which the executed command's standard input is taken. This attribute is mutually
  159. exclusive with the <var>inputstring</var> and <var>inputproperty</var> attributes.<br/> When
  160. executing more than one command via <var>commandResource</var>, input will be read for each
  161. command. <em>since Ant 1.8.0</em></td>
  162. <td>No</td>
  163. </tr>
  164. <tr>
  165. <td>verbose</td>
  166. <td>Determines whether <code>sshexec</code> outputs verbosely to the user.<br/> Similar output
  167. is generated as the <kbd>ssh</kbd> command line tool with the <kbd>-v</kbd>
  168. option. <em>since Ant 1.8.0</em></td>
  169. <td>No; defaults to <q>false</q></td>
  170. </tr>
  171. <tr>
  172. <td>inputproperty</td>
  173. <td>Name of a property content of which serves as the input stream for the executed
  174. command. This attribute is mutually exclusive with the <var>input</var>
  175. and <var>inputstring</var> attributes.<br/> When executing more than one command
  176. via <var>commandResource</var>, input will be read for each command. <em>since Ant
  177. 1.8.0</em></td>
  178. <td>No</td>
  179. </tr>
  180. <tr>
  181. <td>inputstring</td>
  182. <td>A string which serves as the input stream for the executed command. This attribute is
  183. mutually exclusive with the <var>input</var> and <var>inputproperty</var> attributes.<br/>
  184. When executing more than one command via <var>commandResource</var>, input will be read for
  185. each command. <em>since Ant 1.8.3</em></td>
  186. <td>No</td>
  187. </tr>
  188. <tr>
  189. <td>usepty</td>
  190. <td>Whether to allocate a pseudo-tty (like <kbd>ssh -t</kbd>). <em>since Ant 1.8.3</em></td>
  191. <td>No; defaults to <q>false</q></td>
  192. </tr>
  193. <tr>
  194. <td>useSystemIn</td>
  195. <td>Whether to pass the current standard input to the remote process. <em>since Ant
  196. 1.9.4</em></td>
  197. <td>No; defaults to <q>false</q></td>
  198. </tr>
  199. <tr>
  200. <td>serverAliveIntervalSeconds</td>
  201. <td>Sets a timeout interval in seconds after which if no data has been received from the server,
  202. the task will send a message through the encrypted channel to request a response from the
  203. server. <em>since Ant 1.9.7</em></td>
  204. <td>No, the default is <q>0</q>, indicating that these messages will not be sent to the
  205. server</td>
  206. </tr>
  207. <tr>
  208. <td>serverAliveCountMax</td>
  209. <td>The number of server alive messages which may be sent without receiving any messages back
  210. from the server. Only used if <var>serverAliveIntervalSeconds</var> is
  211. not <q>0</q>. <em>since Ant 1.9.7</em></td>
  212. <td>No; defaults to <q>3</q></td>
  213. </tr>
  214. </table>
  215. <h3>Examples</h3>
  216. <p>Run a command on a remote machine using password authentication</p>
  217. <pre>
  218. &lt;sshexec host=&quot;somehost&quot;
  219. username=&quot;dude&quot;
  220. password=&quot;yo&quot;
  221. command=&quot;touch somefile&quot;/&gt;</pre>
  222. <p>Run a command on a remote machine using key authentication</p>
  223. <pre>
  224. &lt;sshexec host=&quot;somehost&quot;
  225. username=&quot;dude&quot;
  226. keyfile=&quot;${user.home}/.ssh/id_dsa&quot;
  227. passphrase=&quot;yo its a secret&quot;
  228. command=&quot;touch somefile&quot;/&gt;</pre>
  229. <p>Run a command on a remote machine using key authentication with no passphrase</p>
  230. <pre>
  231. &lt;sshexec host=&quot;somehost&quot;
  232. username=&quot;dude&quot;
  233. keyfile=&quot;${user.home}/.ssh/id_dsa&quot;
  234. command=&quot;touch somefile&quot;/&gt;</pre>
  235. <p>Run a set of commands from a command resource (file) on a remote machine using key authentication
  236. with no passphrase</p>
  237. <pre>
  238. &lt;sshexec host=&quot;somehost&quot;
  239. username=&quot;dude&quot;
  240. keyfile=&quot;${user.home}/.ssh/id_dsa&quot;
  241. commandResource=&quot;to_run&quot;/&gt;</pre>
  242. <p><strong>Security Note</strong>: Hardcoding passwords and/or usernames in <var>sshexec</var> task
  243. can be a serious security hole. Consider using variable substitution and include the password on the
  244. command line. For example:</p>
  245. <pre>
  246. &lt;sshexec host=&quot;somehost&quot;
  247. username=&quot;${username}&quot;
  248. password=&quot;${password}&quot;
  249. command=&quot;touch somefile&quot;/&gt;</pre>
  250. <p>Invoking Ant with the following command line:</p>
  251. <pre class="input">ant -Dusername=me -Dpassword=mypassword target1 target2</pre>
  252. <p>is slightly better, but the username/password is exposed to all users on an Unix system (via
  253. the <kbd>ps</kbd> command). The best approach is to use the <code>&lt;input&gt;</code> task and/or
  254. retrieve the password from a (secured) <samp>.properties</samp> file.</p>
  255. </body>
  256. </html>