net-ssh 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. data/doc/LICENSE-BSD +27 -0
  2. data/doc/LICENSE-GPL +280 -0
  3. data/doc/LICENSE-RUBY +56 -0
  4. data/doc/README +13 -0
  5. data/doc/manual-html/chapter-1.html +333 -0
  6. data/doc/manual-html/chapter-2.html +455 -0
  7. data/doc/manual-html/chapter-3.html +413 -0
  8. data/doc/manual-html/chapter-4.html +353 -0
  9. data/doc/manual-html/chapter-5.html +393 -0
  10. data/doc/manual-html/chapter-6.html +296 -0
  11. data/doc/manual-html/index.html +217 -0
  12. data/doc/manual-html/manual.css +192 -0
  13. data/doc/manual/chapter.erb +18 -0
  14. data/doc/manual/example.erb +18 -0
  15. data/doc/manual/index.erb +29 -0
  16. data/doc/manual/manual.css +192 -0
  17. data/doc/manual/manual.rb +240 -0
  18. data/doc/manual/manual.yml +67 -0
  19. data/doc/manual/page.erb +87 -0
  20. data/doc/manual/parts/channels_callbacks.txt +32 -0
  21. data/doc/manual/parts/channels_loop.txt +14 -0
  22. data/doc/manual/parts/channels_open.txt +20 -0
  23. data/doc/manual/parts/channels_operations.txt +15 -0
  24. data/doc/manual/parts/channels_types.txt +3 -0
  25. data/doc/manual/parts/channels_what_are.txt +7 -0
  26. data/doc/manual/parts/exec_channels.txt +28 -0
  27. data/doc/manual/parts/exec_open.txt +51 -0
  28. data/doc/manual/parts/exec_popen3.txt +35 -0
  29. data/doc/manual/parts/forward_direct.txt +37 -0
  30. data/doc/manual/parts/forward_handlers.txt +16 -0
  31. data/doc/manual/parts/forward_intro.txt +18 -0
  32. data/doc/manual/parts/forward_local.txt +18 -0
  33. data/doc/manual/parts/forward_remote.txt +14 -0
  34. data/doc/manual/parts/intro_author.txt +1 -0
  35. data/doc/manual/parts/intro_getting.txt +39 -0
  36. data/doc/manual/parts/intro_license.txt +6 -0
  37. data/doc/manual/parts/intro_support.txt +7 -0
  38. data/doc/manual/parts/intro_what_is.txt +7 -0
  39. data/doc/manual/parts/intro_what_is_not.txt +3 -0
  40. data/doc/manual/parts/proxy_http.txt +52 -0
  41. data/doc/manual/parts/proxy_intro.txt +1 -0
  42. data/doc/manual/parts/proxy_socks.txt +23 -0
  43. data/doc/manual/parts/session_key.txt +66 -0
  44. data/doc/manual/parts/session_options.txt +42 -0
  45. data/doc/manual/parts/session_session.txt +14 -0
  46. data/doc/manual/parts/session_start.txt +49 -0
  47. data/doc/manual/tutorial.erb +30 -0
  48. data/examples/channel-demo.rb +81 -0
  49. data/examples/port-forward.rb +51 -0
  50. data/examples/process-demo.rb +91 -0
  51. data/examples/remote-net-port-forward.rb +45 -0
  52. data/examples/remote-port-forward.rb +80 -0
  53. data/examples/tail-demo.rb +49 -0
  54. data/lib/net/ssh.rb +52 -0
  55. data/lib/net/ssh/connection/channel.rb +411 -0
  56. data/lib/net/ssh/connection/constants.rb +47 -0
  57. data/lib/net/ssh/connection/driver.rb +343 -0
  58. data/lib/net/ssh/connection/services.rb +72 -0
  59. data/lib/net/ssh/connection/term.rb +90 -0
  60. data/lib/net/ssh/errors.rb +27 -0
  61. data/lib/net/ssh/proxy/errors.rb +34 -0
  62. data/lib/net/ssh/proxy/http.rb +126 -0
  63. data/lib/net/ssh/proxy/socks4.rb +83 -0
  64. data/lib/net/ssh/proxy/socks5.rb +160 -0
  65. data/lib/net/ssh/service/forward/driver.rb +319 -0
  66. data/lib/net/ssh/service/forward/local-network-handler.rb +74 -0
  67. data/lib/net/ssh/service/forward/remote-network-handler.rb +81 -0
  68. data/lib/net/ssh/service/forward/services.rb +76 -0
  69. data/lib/net/ssh/service/process/driver.rb +153 -0
  70. data/lib/net/ssh/service/process/open.rb +193 -0
  71. data/lib/net/ssh/service/process/popen3.rb +160 -0
  72. data/lib/net/ssh/service/process/services.rb +66 -0
  73. data/lib/net/ssh/service/services.rb +44 -0
  74. data/lib/net/ssh/session.rb +242 -0
  75. data/lib/net/ssh/transport/algorithm-negotiator.rb +267 -0
  76. data/lib/net/ssh/transport/compress/compressor.rb +53 -0
  77. data/lib/net/ssh/transport/compress/decompressor.rb +53 -0
  78. data/lib/net/ssh/transport/compress/none-compressor.rb +39 -0
  79. data/lib/net/ssh/transport/compress/none-decompressor.rb +39 -0
  80. data/lib/net/ssh/transport/compress/services.rb +68 -0
  81. data/lib/net/ssh/transport/compress/zlib-compressor.rb +60 -0
  82. data/lib/net/ssh/transport/compress/zlib-decompressor.rb +52 -0
  83. data/lib/net/ssh/transport/constants.rb +66 -0
  84. data/lib/net/ssh/transport/errors.rb +47 -0
  85. data/lib/net/ssh/transport/identity-cipher.rb +61 -0
  86. data/lib/net/ssh/transport/kex/dh-gex.rb +106 -0
  87. data/lib/net/ssh/transport/kex/dh.rb +231 -0
  88. data/lib/net/ssh/transport/kex/services.rb +60 -0
  89. data/lib/net/ssh/transport/ossl/buffer-factory.rb +52 -0
  90. data/lib/net/ssh/transport/ossl/buffer.rb +87 -0
  91. data/lib/net/ssh/transport/ossl/cipher-factory.rb +98 -0
  92. data/lib/net/ssh/transport/ossl/digest-factory.rb +51 -0
  93. data/lib/net/ssh/transport/ossl/hmac-factory.rb +71 -0
  94. data/lib/net/ssh/transport/ossl/hmac/hmac.rb +62 -0
  95. data/lib/net/ssh/transport/ossl/hmac/md5-96.rb +44 -0
  96. data/lib/net/ssh/transport/ossl/hmac/md5.rb +46 -0
  97. data/lib/net/ssh/transport/ossl/hmac/none.rb +46 -0
  98. data/lib/net/ssh/transport/ossl/hmac/services.rb +68 -0
  99. data/lib/net/ssh/transport/ossl/hmac/sha1-96.rb +44 -0
  100. data/lib/net/ssh/transport/ossl/hmac/sha1.rb +45 -0
  101. data/lib/net/ssh/transport/ossl/key-factory.rb +113 -0
  102. data/lib/net/ssh/transport/ossl/services.rb +149 -0
  103. data/lib/net/ssh/transport/packet-stream.rb +210 -0
  104. data/lib/net/ssh/transport/services.rb +146 -0
  105. data/lib/net/ssh/transport/session.rb +296 -0
  106. data/lib/net/ssh/transport/version-negotiator.rb +73 -0
  107. data/lib/net/ssh/userauth/agent.rb +218 -0
  108. data/lib/net/ssh/userauth/constants.rb +35 -0
  109. data/lib/net/ssh/userauth/driver.rb +176 -0
  110. data/lib/net/ssh/userauth/methods/hostbased.rb +119 -0
  111. data/lib/net/ssh/userauth/methods/password.rb +70 -0
  112. data/lib/net/ssh/userauth/methods/publickey.rb +137 -0
  113. data/lib/net/ssh/userauth/methods/services.rb +63 -0
  114. data/lib/net/ssh/userauth/services.rb +126 -0
  115. data/lib/net/ssh/userauth/userkeys.rb +258 -0
  116. data/lib/net/ssh/util/buffer.rb +274 -0
  117. data/lib/net/ssh/util/openssl.rb +146 -0
  118. data/lib/net/ssh/util/prompter.rb +73 -0
  119. data/lib/net/ssh/version.rb +29 -0
  120. data/test/ALL-TESTS.rb +21 -0
  121. data/test/connection/tc_channel.rb +136 -0
  122. data/test/connection/tc_driver.rb +287 -0
  123. data/test/connection/tc_integration.rb +85 -0
  124. data/test/proxy/tc_http.rb +209 -0
  125. data/test/proxy/tc_socks4.rb +148 -0
  126. data/test/proxy/tc_socks5.rb +214 -0
  127. data/test/service/forward/tc_driver.rb +289 -0
  128. data/test/service/forward/tc_local_network_handler.rb +123 -0
  129. data/test/service/forward/tc_remote_network_handler.rb +108 -0
  130. data/test/service/process/tc_driver.rb +79 -0
  131. data/test/service/process/tc_integration.rb +117 -0
  132. data/test/service/process/tc_open.rb +179 -0
  133. data/test/service/process/tc_popen3.rb +164 -0
  134. data/test/tc_integration.rb +79 -0
  135. data/test/transport/compress/tc_none_compress.rb +41 -0
  136. data/test/transport/compress/tc_none_decompress.rb +45 -0
  137. data/test/transport/compress/tc_zlib_compress.rb +61 -0
  138. data/test/transport/compress/tc_zlib_decompress.rb +48 -0
  139. data/test/transport/kex/tc_dh.rb +304 -0
  140. data/test/transport/kex/tc_dh_gex.rb +70 -0
  141. data/test/transport/ossl/fixtures/dsa-encrypted +15 -0
  142. data/test/transport/ossl/fixtures/dsa-encrypted-bad +15 -0
  143. data/test/transport/ossl/fixtures/dsa-unencrypted +12 -0
  144. data/test/transport/ossl/fixtures/dsa-unencrypted-bad +12 -0
  145. data/test/transport/ossl/fixtures/dsa-unencrypted.pub +1 -0
  146. data/test/transport/ossl/fixtures/not-a-private-key +4 -0
  147. data/test/transport/ossl/fixtures/not-supported +2 -0
  148. data/test/transport/ossl/fixtures/rsa-encrypted +18 -0
  149. data/test/transport/ossl/fixtures/rsa-encrypted-bad +18 -0
  150. data/test/transport/ossl/fixtures/rsa-unencrypted +15 -0
  151. data/test/transport/ossl/fixtures/rsa-unencrypted-bad +15 -0
  152. data/test/transport/ossl/fixtures/rsa-unencrypted.pub +1 -0
  153. data/test/transport/ossl/hmac/tc_hmac.rb +58 -0
  154. data/test/transport/ossl/hmac/tc_md5.rb +50 -0
  155. data/test/transport/ossl/hmac/tc_md5_96.rb +50 -0
  156. data/test/transport/ossl/hmac/tc_none.rb +50 -0
  157. data/test/transport/ossl/hmac/tc_sha1.rb +50 -0
  158. data/test/transport/ossl/hmac/tc_sha1_96.rb +50 -0
  159. data/test/transport/ossl/tc_buffer.rb +97 -0
  160. data/test/transport/ossl/tc_buffer_factory.rb +67 -0
  161. data/test/transport/ossl/tc_cipher_factory.rb +84 -0
  162. data/test/transport/ossl/tc_digest_factory.rb +39 -0
  163. data/test/transport/ossl/tc_hmac_factory.rb +72 -0
  164. data/test/transport/ossl/tc_key_factory.rb +199 -0
  165. data/test/transport/tc_algorithm_negotiator.rb +169 -0
  166. data/test/transport/tc_identity_cipher.rb +52 -0
  167. data/test/transport/tc_integration.rb +110 -0
  168. data/test/transport/tc_packet_stream.rb +183 -0
  169. data/test/transport/tc_session.rb +283 -0
  170. data/test/transport/tc_version_negotiator.rb +86 -0
  171. data/test/userauth/methods/tc_hostbased.rb +136 -0
  172. data/test/userauth/methods/tc_password.rb +89 -0
  173. data/test/userauth/methods/tc_publickey.rb +167 -0
  174. data/test/userauth/tc_agent.rb +223 -0
  175. data/test/userauth/tc_driver.rb +190 -0
  176. data/test/userauth/tc_integration.rb +81 -0
  177. data/test/userauth/tc_userkeys.rb +265 -0
  178. data/test/util/tc_buffer.rb +217 -0
  179. metadata +256 -0
@@ -0,0 +1,455 @@
1
+ <html>
2
+ <head>
3
+ <title>Net::SSH Manual :: Chapter 2: Starting a Session</title>
4
+ <link type="text/css" rel="stylesheet" href="manual.css" />
5
+ </head>
6
+
7
+ <body>
8
+ <div id="banner">
9
+ <table border='0' cellpadding='0' cellspacing='0' width='100%'>
10
+ <tr><td valign='top' align='left'>
11
+ <div class="title">
12
+ <span class="product">Net::SSH&mdash;</span><br />
13
+ <span class="tagline">Secure Shell for Ruby</span>
14
+ </div>
15
+ </td><td valign='middle' align='right'>
16
+ <div class="info">
17
+ Net::SSH Version: <strong>0.5.0</strong><br />
18
+ Manual Last Updated: <strong>2004-11-23 20:18 GMT</strong>
19
+ </div>
20
+ </td></tr>
21
+ </table>
22
+ </div>
23
+
24
+ <table border='0' width='100%' cellpadding='0' cellspacing='0'>
25
+ <tr><td valign='top'>
26
+
27
+ <div id="navigation">
28
+ <h1>Net::SSH Manual</h1>
29
+
30
+ <h2>Chapters</h2>
31
+ <ol type="I">
32
+
33
+ <li>
34
+ <a href="chapter-1.html">
35
+ Introduction
36
+ </a>
37
+
38
+ <ol type="1">
39
+
40
+ <li><a href="chapter-1.html#s1">What is Net::SSH?</a></li>
41
+
42
+ <li><a href="chapter-1.html#s2">What isn&#8217;t Net::SSH?</a></li>
43
+
44
+ <li><a href="chapter-1.html#s3">Getting Net::SSH</a></li>
45
+
46
+ <li><a href="chapter-1.html#s4">License Information</a></li>
47
+
48
+ <li><a href="chapter-1.html#s5">Support</a></li>
49
+
50
+ <li><a href="chapter-1.html#s6">About the Author</a></li>
51
+
52
+ </ol>
53
+ </li>
54
+
55
+ <li><strong>
56
+ <a href="chapter-2.html">
57
+ Starting a Session
58
+ </a>
59
+ </strong> <big>&larr;</big>
60
+ <ol type="1">
61
+
62
+ <li><a href="chapter-2.html#s1">Using Net::SSH.start</a></li>
63
+
64
+ <li><a href="chapter-2.html#s2">Using a Public/Private Key</a></li>
65
+
66
+ <li><a href="chapter-2.html#s3">Options</a></li>
67
+
68
+ <li><a href="chapter-2.html#s4">Using Net::SSH::Session</a></li>
69
+
70
+ </ol>
71
+ </li>
72
+
73
+ <li>
74
+ <a href="chapter-3.html">
75
+ Channels
76
+ </a>
77
+
78
+ <ol type="1">
79
+
80
+ <li><a href="chapter-3.html#s1">What are Channels?</a></li>
81
+
82
+ <li><a href="chapter-3.html#s2">Session.loop</a></li>
83
+
84
+ <li><a href="chapter-3.html#s3">Channel Types</a></li>
85
+
86
+ <li><a href="chapter-3.html#s4">Opening a Channel</a></li>
87
+
88
+ <li><a href="chapter-3.html#s5">Callbacks</a></li>
89
+
90
+ <li><a href="chapter-3.html#s6">Channel Operations</a></li>
91
+
92
+ </ol>
93
+ </li>
94
+
95
+ <li>
96
+ <a href="chapter-4.html">
97
+ Executing Commands
98
+ </a>
99
+
100
+ <ol type="1">
101
+
102
+ <li><a href="chapter-4.html#s1">Using Channels</a></li>
103
+
104
+ <li><a href="chapter-4.html#s2">Using #process.open</a></li>
105
+
106
+ <li><a href="chapter-4.html#s3">Using #process.popen3</a></li>
107
+
108
+ </ol>
109
+ </li>
110
+
111
+ <li>
112
+ <a href="chapter-5.html">
113
+ Port Forwarding
114
+ </a>
115
+
116
+ <ol type="1">
117
+
118
+ <li><a href="chapter-5.html#s1">Introduction</a></li>
119
+
120
+ <li><a href="chapter-5.html#s2">Local-to-Remote</a></li>
121
+
122
+ <li><a href="chapter-5.html#s3">Remote-to-Local</a></li>
123
+
124
+ <li><a href="chapter-5.html#s4">Direct Channels</a></li>
125
+
126
+ <li><a href="chapter-5.html#s5">Remote-to-Local Handlers</a></li>
127
+
128
+ </ol>
129
+ </li>
130
+
131
+ <li>
132
+ <a href="chapter-6.html">
133
+ Using Proxies
134
+ </a>
135
+
136
+ <ol type="1">
137
+
138
+ <li><a href="chapter-6.html#s1">Introduction</a></li>
139
+
140
+ <li><a href="chapter-6.html#s2"><span class="caps">HTTP</span></a></li>
141
+
142
+ <li><a href="chapter-6.html#s3"><span class="caps">SOCKS</span></a></li>
143
+
144
+ </ol>
145
+ </li>
146
+
147
+ </ol>
148
+
149
+ <h2>Other Documentation</h2>
150
+
151
+ <ul>
152
+ <li><a href="http://net-ssh.rubyforge.org/api/index.html">Net::SSH API</a></li>
153
+ <li><a href="http://rubyforge.org/tracker/?atid=1842&group_id=274&func=browse">Net::SSH FAQ</a></li>
154
+ </ul>
155
+
156
+ <h2>Tutorials</h2>
157
+ <ol>
158
+
159
+ </ol>
160
+
161
+ <p align="center"><strong>More To Come...</strong></p>
162
+
163
+ <div class="license">
164
+ <a href="http://creativecommons.org/licenses/by-sa/2.0/"><img alt="Creative Commons License" border="0" src="http://creativecommons.org/images/public/somerights" /></a><br />
165
+ This manual is licensed under a <a href="http://creativecommons.org/licenses/by-sa/2.0/">Creative Commons License</a>.
166
+ </div>
167
+ </div>
168
+
169
+ </td><td valign='top' width="100%">
170
+
171
+ <div id="content">
172
+
173
+ <h1>2. Starting a Session</h1>
174
+
175
+
176
+
177
+ <h2>
178
+ <a name="s1"></a>
179
+ 2.1. Using Net::SSH.start
180
+ </h2>
181
+
182
+
183
+
184
+ <div class="section">
185
+ <p>Before you can do anything with Net::SSH, you need to require the <code>net/ssh</code> module:</p>
186
+
187
+
188
+ <pre>
189
+ require 'net/ssh'
190
+ </pre>
191
+ <p>Once you have required the <code>net/ssh</code> module, you can begin an <span class="caps">SSH</span> session by calling <code>Net::SSH.start</code>. This may be used in one of two ways. If called without a block, it will return a reference to the new session as an instance of a <code>Net::SSH::Session</code>. Used this way, you must explicitly close the session when you are finished with it.</p>
192
+
193
+
194
+ <pre>
195
+ session = Net::SSH.start( 'host', 'user', 'passwd' )
196
+ ...
197
+ session.close
198
+ </pre>
199
+ <p>The other approach involves attaching a block to the start method. When used this way, the new session is passed to the block, and the session is automatically closed when the block exits.</p>
200
+
201
+
202
+ <pre>
203
+ Net::SSH.start( 'host', 'user', 'passwd' ) do |session|
204
+ ...
205
+ end
206
+ </pre>
207
+ <p>If you need to specify a different port on the host to connect to (the default is 22), you can specify it immediately after the <code>host</code> parameter, like so:</p>
208
+
209
+
210
+ <pre>
211
+ Net::SSH.start( 'host', 1234, 'user', 'passwd' ) do |session|
212
+ ...
213
+ end
214
+ </pre>
215
+ <h3>Using Keyword Arguments</h3>
216
+
217
+ <p>Some people prefer using keyword arguments for functions with more than a couple of parameters. The <code>start</code> method supports this approach as well, although the <code>host</code> parameter is always positional and always comes first.</p>
218
+
219
+
220
+ <pre>
221
+ Net::SSH.start( 'host',
222
+ :password=&gt;'passwd',
223
+ :port=&gt;1234,
224
+ :username=&gt;'user',
225
+ ... ) do |session|
226
+ ...
227
+ end
228
+ </pre>
229
+ <p>(More about the &#8220;<code>...</code>&#8221; stuff, later.)</p>
230
+
231
+ <h3>Failed Authentication</h3>
232
+
233
+ <p>If the username and/or password given to <code>start</code> are incorrect, authentication will fail. If authentication fails, a <code>Net::SSH::AuthenticationFailed</code> exception will be raised.</p>
234
+ </div>
235
+
236
+
237
+
238
+ <h2>
239
+ <a name="s2"></a>
240
+ 2.2. Using a Public/Private Key
241
+ </h2>
242
+
243
+
244
+
245
+ <div class="section">
246
+ <p>Just as with the <a href="http://www.openssh.org">OpenSSH</a> version of the <code>ssh</code> utilities, Net::SSH supports authentication using public/private keys.</p>
247
+
248
+ <h3>I don&#8217;t know what public/private keys are&#8230; Explain, please?</h3>
249
+
250
+ <p>Public key/private key encryption is just one way of hiding information from prying eyes. The idea is that you have two tokens: a <em>public key</em>, and a <em>private key</em>. The private key is yours alone&#8212;you never let <em>anyone</em> else see it. The <em>public key</em>, on the other hand, is distributable. You give it to anyone that you want to be able to communicate with you securely.</p>
251
+
252
+ <p>The remote party uses your public key to encrypt information. Anything encrypted with your public key may only be decrypted with the corresponding private key, and since you have the only copy of that, you can rest easily knowing that no one can easily intercept your communications!</p>
253
+
254
+ <p>Net::SSH allows you to define a private key, which it will then attempt to use during authentication with the remote server. If the remote server has a copy of the corresponding public key, you will be able to log into that remote server without having to specify a password. Not only is this convenient, but for Ruby scripts, it is much more secure, since you don&#8217;t have to hard-code your password in your script.</p>
255
+
256
+ <h3>Setting up public/private keys</h3>
257
+
258
+ <p>Net::SSH, by default, will use the private keys that you have set up for use with ssh. These keys are called &#8220;id_dsa&#8221; and &#8220;id_rsa&#8221;, and are located under your home directory, either in a &#8221;.ssh&#8221; subdirectory, or a &#8221;.ssh2&#8221; subdirectory.</p>
259
+
260
+ <p>The &#8220;id_dsa&#8221; key is the preferred key (since it uses the stronger <span class="caps">DSA</span> encryption), but both <span class="caps">DSA</span> and <span class="caps">RSA</span> are supported.</p>
261
+
262
+ <p>To create these keys, you can use the &#8220;ssh-keygen&#8221; utility from <a href="http://www.openssh.org">OpenSSH</a>. Alternatively, if you have the Net::SSH::Utilities package installed, you can use the &#8220;rb-keygen&#8221; utility (which is a pure-Ruby implementation of most of the functionality of ssh-keygen).</p>
263
+
264
+
265
+ <pre>
266
+ ssh-keygen -t dsa
267
+ </pre>
268
+ <p>(If you would rather use an <span class="caps">RSA</span> key, replace &#8220;dsa&#8221; with &#8220;rsa&#8221; in the command given above.)</p>
269
+
270
+ <p>Accept all the defaults when prompted. You will also be asked for a passphrase. This passphrase is an additional level of protection, which prevents anyone from being able to use your private key without knowing the passphrase. Unfortunately, it also means that you have to enter the passphrase every time you use your key. It is up to you what price you want to pay for security, but if you <em>can</em> leave the passphrase blank. In this case, anyone that has a copy of your private key can use it, but it&#8217;s a little more convenient to deal with.</p>
271
+
272
+ <p>Once you create your keys, you then need to set up your account on each remote server so that it knows about your public key. To do this, log into the remote server and edit (or create) the file (in your home directory) &#8221;.ssh/authorized_keys&#8221;. Just copy the contents of your public key (in your local machine&#8217;s home directory, called &#8221;.ssh/id_dsa.pub&#8221; or &#8221;.ssh/id_rsa.pub&#8221;) into the &#8220;authorized_keys&#8221; file on a line of its own. Then save the file and logout. Everything <em>should</em> now be set up.</p>
273
+
274
+ <p>(Note: if you have an <span class="caps">SSH</span> client installed, it will typically have its own key generation utility. You can use that instead, if you prefer.)</p>
275
+
276
+ <h3>Connecting using public/private keys</h3>
277
+
278
+ <p>Public/private keys are always tried before the explicit password authentication, even if you provide a password. Thus, if you <em>only</em> want to use public/private key authentication, simply remove the password from the argument list. If you can successfully obtain a session handle, then your keys are set up correctly!</p>
279
+
280
+
281
+ <pre>
282
+ Net::SSH.start( 'host', 'user' ) do |session|
283
+ ...
284
+ end
285
+ </pre>
286
+ <p>Furthermore, if your <code>USER</code> environment variable is set to the username that you want to log into the remote machine as, you can even leave the <code>username</code> parameter off:</p>
287
+
288
+
289
+ <pre>
290
+ Net::SSH.start( 'host' ) do |session|
291
+ ...
292
+ end
293
+ </pre>
294
+ <h3>Using keys with passphrases</h3>
295
+
296
+ <p>When you use a private key that was created with a passphrase, you will be prompted to enter the passphrase when the key is loaded. This may make such a key inappropriate for use in automated environments, but it is certainly more secure than the use of unprotected private keys.</p>
297
+
298
+ <p>If you have the <a href="http://raa.ruby-lang.org/project/ruby-termios">ruby-termios</a> and <a href="http://raa.ruby-lang.org/project/ruby-password">ruby-password</a> modules installed, the ruby-password module will be used when prompting for passphrases. Otherwise, a generic message (courtesy of the OpenSSL library) will be presented, which will not be very informative.</p>
299
+
300
+ <h3>Using an <span class="caps">SSH</span> agent</h3>
301
+
302
+ <p>Most <span class="caps">SSH</span> clients come with what is called an <em>agent</em>. This is a program that is continually running, and which keeps track of all of a user&#8217;s keys. When an <span class="caps">SSH</span> client needs to perform an operation using one of the user&#8217;s keys, it requests the operation via the agent, rather than performing the operation itself directly with a key.</p>
303
+
304
+ <p>The benefit of this is what is known as <em>single sign-on</em>. If any of your keys have a passphrase, this allows you to enter the passphrase <em>once</em> (when the key is loaded by the agent), and then any <span class="caps">SSH</span> program you use will never prompt you for that passphrase again.</p>
305
+
306
+ <p>Net::SSH includes support for interfacing with an <span class="caps">SSH</span> agent. Currently, only Unix-ish systems are supported (due to issues with interprocess communication on Windows). Eventually, perhaps an interface will be created to the <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/" title="pageant">PuTTY agent</a>, but don&#8217;t hold your breath. (It&#8217;s not very easy to interface with.)</p>
307
+
308
+ <p>To allow your Net::SSH programs to interface with a running agent, simply make sure that the <code>SSH_AGENT_SOCK</code> environment variable is set to the location of the Unix domain socket that the agent is listening to. Also, make sure you have added all of your keys to the agent (typically by running the <code>ssh-add</code> utility.</p>
309
+
310
+ <p>A future version of Net::SSH may include it&#8217;s own agent implementation as well, to make using an agent on a variety of platforms simpler.</p>
311
+ </div>
312
+
313
+
314
+
315
+ <h2>
316
+ <a name="s3"></a>
317
+ 2.3. Options
318
+ </h2>
319
+
320
+
321
+
322
+ <div class="section">
323
+ <p>There are various additional options that you can specify when connecting. These options allow you to specify such things as the cipher algorithm to use, whether or not the data stream will be compressed, or explicit paths to the private keys to use.</p>
324
+
325
+ <p>Options are specified as a hash in the last parameter to the <code>start</code> method. If using the keyword parameters version of the <code>start</code> method, the options hash is whatever is left after processing the <code>:username</code>, <code>:password</code>, and <code>:port</code> options.</p>
326
+
327
+ <p>The complete list of available options, and their valid values, is given in the following table.</p>
328
+
329
+ <table class="list">
330
+ <tr>
331
+ <th>Option </th>
332
+ <th>Description </th>
333
+ </tr>
334
+ <tr>
335
+ <td style="vertical-align:top;text-align:center;"><code>:auth_methods</code> </td>
336
+ <td> This is the list of authorization methods to try. It defaults to &#8220;publickey&#8221;, &#8220;keyboard-interactive&#8221;, &#8220;password&#8221;, and &#8220;hostbased&#8221;. (These are also the only authorization methods that are supported.) If you want them to be tried in a different order, or if you don&#8217;t want certain methods to be used, you can specify your own list via this option.</td>
337
+ </tr>
338
+ <tr>
339
+ <td style="vertical-align:top;text-align:center;"><code>:compression</code> </td>
340
+ <td> The compression algorithm to use when compressing the data stream. Valid values are <code>none</code> and <code>zlib</code>. The default is <code>none</code>.</td>
341
+ </tr>
342
+ <tr>
343
+ <td style="vertical-align:top;text-align:center;"><code>:compression_level</code> </td>
344
+ <td> This is only used when the compression algorithm is <code>zlib</code>. It is an integer value from 0 to 9, representing the quality of the compression. <span class="caps">A 0</span> is no compression, and a 9 is most compression. The default is 6.</td>
345
+ </tr>
346
+ <tr>
347
+ <td style="vertical-align:top;text-align:center;"><code>:container</code> </td>
348
+ <td> This is the dependency injection container to use when registering all of the services that Net::SSH uses internally. If unspecified (the default) a new container will be created. This option allows you to reuse a single container for multiple application components.</td>
349
+ </tr>
350
+ <tr>
351
+ <td style="vertical-align:top;text-align:center;"><code>:crypto_backend</code> </td>
352
+ <td> This is the cryptography backend to use. It defaults to <code>:ossl</code>, which specifies the OpenSSL cryptography engine. Currently, this is the only supported backend, but in the future others may be provided, and this is how they would be selected.</td>
353
+ </tr>
354
+ <tr>
355
+ <td style="vertical-align:top;text-align:center;"><code>:encryption</code> </td>
356
+ <td> This is the cipher algorithm to use when sending/receiving data to/from the remote server. It defaults to <code>3des-cbc</code>. Other valid algorithms supported by Net::SSH are <code>aes128-cbc</code>, <code>blowfish-cbc</code>, <code>aes256-cbc</code>, <code>aes192-cbc</code>, <code>idea-cbc</code>, and <code>none</code>. Note that the values you specify here are only <em>suggestions</em>, and if the server you are contacting cannot use your recommended algorithm, a fallback algorithm will be used (typically chosen in the order the algorithms were listed, above). This option may take an array, if you want to specify the order of the fallback algorithms to try, as well. </td>
357
+ </tr>
358
+ <tr>
359
+ <td style="vertical-align:top;text-align:center;"><code>:hmac</code> </td>
360
+ <td> This specifies the &#8220;message authentication code&#8221; (MAC) algorithm to use to ensure that each packet transmitted and recieved is authentic. This defaults to <code>hmac-md5</code>. Other valid algorithms supported by Net::SSH are <code>hmac-sha1</code>, <code>hmac-md5-96</code>, <code>hmac-md5-sha1</code>, and <code>none</code>. Note that the values you specify here are only <em>suggestions</em>, and if the server you are contacting cannot use your recommended algorithm, a fallback algorithm will be used (typically chosen in the order the algorithms were listed, above). This option may take an array, if you want to specify the order of the fallback algorithms to try, as well. </td>
361
+ </tr>
362
+ <tr>
363
+ <td style="vertical-align:top;text-align:center;"><code>:host_key</code> </td>
364
+ <td> This specifies the host key type that should be used when negotiating keys with the server. This defaults to <code>ssh-dss</code>, but may also be <code>ssh-rsa</code>. As with some other option types, the value you specify is only a recommendation, not a commandment, and if the server cannot honor the key type you specified, a fallback will be chosen from among the other supported types. If you wish to specify the fallback algorithms to try, you may pass an array as the value of this option, which contains (in order) the key types to try. </td>
365
+ </tr>
366
+ <tr>
367
+ <td style="vertical-align:top;text-align:center;"><code>:host_keys</code> </td>
368
+ <td> This is an array of file names that contain the private keys which identify the host your script is running on. These default to <code>/etc/ssh/ssh_host_dsa_key</code> and <code>/etc/ssh/ssh_host_rsa_key</code> (which are both typically only readable by root). These keys are only used in hostbased authentication.</td>
369
+ </tr>
370
+ <tr>
371
+ <td style="vertical-align:top;text-align:center;"><code>:kex</code> </td>
372
+ <td> This specifies the &#8220;key-exchange&#8221; (KEX) algorithm to use when exchanging keys. Two algorithms are currently supported: <code>diffie-hellman-group-exchange-sha1</code>, and <code>diffie-hellman-group1-sha1</code>. The default is <code>diffie-hellman-group-exchange-sha1</code>.</td>
373
+ </tr>
374
+ <tr>
375
+ <td style="vertical-align:top;text-align:center;"><code>:keys</code> </td>
376
+ <td> This specifies the list of private key files to use <em>instead</em> of the defaults (<code>$HOME/.ssh/id_dsa</code>, <code>$HOME/.ssh2/id_dsa</code>, <code>$HOME/.ssh/id_rsa</code>, and <code>$HOME/.ssh2/id_rsa</code>). The value of this option should be an array of strings.</td>
377
+ </tr>
378
+ <tr>
379
+ <td style="vertical-align:top;text-align:center;"><code>:languages</code> </td>
380
+ <td> This option specifies the preferred language (or languages) that should be used when communicating error messages. It has no effect on Net::SSH, but may cause the server (if it supports your suggested language) to send errors in the language you request. The default is empty.</td>
381
+ </tr>
382
+ <tr>
383
+ <td style="vertical-align:top;text-align:center;"><code>:log</code> </td>
384
+ <td> Specifies either a string or an IO object. If it is a string, it names the file that all log messages should be written to. Otherwise, the messages will be written to the IO object directly. Defaults to <span class="caps">STDERR</span>.</td>
385
+ </tr>
386
+ <tr>
387
+ <td style="vertical-align:top;text-align:center;"><code>:port</code> </td>
388
+ <td> This is the port number that should be used to connect to the remote machine. If you wish to specify the port, you are generally better off specifying it as the second parameter to <code>start</code>, rather than as an option, but you <em>can</em> specify it this way, if you prefer.</td>
389
+ </tr>
390
+ <tr>
391
+ <td style="vertical-align:top;text-align:center;"><code>:registry_options</code> </td>
392
+ <td> If the <code>:container</code> option is not specified, a new container will be created. This option specifies a hash of additional options that may be used to configure the new container (registry). By default, it is empty.</td>
393
+ </tr>
394
+ <tr>
395
+ <td style="vertical-align:top;text-align:center;"><code>:verbose</code> </td>
396
+ <td> Specifies how verbose the logging should be. Valid values are <code>:fatal</code>, <code>:error</code>, <code>:warn</code>, <code>:info</code>, and <code>:debug</code>. Defaults to <code>:warn</code>. <span class="caps">WARNING</span>: selecting <code>:debug</code> will result in <span class="caps">LOTS</span> of output! (Further customization of verbosity can be accomplished by specifying which Net::SSH components should have which logging levels, via the <code>:registry_options</code> option.)</td>
397
+ </tr>
398
+ </table>
399
+
400
+
401
+
402
+ <p>For example, the following code snippet will connect to the given remote host, and requests that the <code>ssh-rsa</code> host key type be used, with the <code>blowfish-cbc</code> cipher algorithm, and requests that the given private key file be used. Also, the data stream will be compressed.</p>
403
+
404
+
405
+ <pre>
406
+ require 'net/ssh'
407
+ require 'logger'
408
+
409
+ Net::SSH.start(
410
+ 'host', 'user',
411
+ :host_key =&gt; "ssh-rsa",
412
+ :encryption =&gt; "blowfish-cbc",
413
+ :keys =&gt; [ "/tmp/temporary-key" ],
414
+ :compression =&gt; "zlib"
415
+ ) do |session|
416
+ ...
417
+ end
418
+ </pre>
419
+ </div>
420
+
421
+
422
+
423
+ <h2>
424
+ <a name="s4"></a>
425
+ 2.4. Using Net::SSH::Session
426
+ </h2>
427
+
428
+
429
+
430
+ <div class="section">
431
+ <p>Alternatively, you can use Net::SSH::Session to start your <span class="caps">SSH</span> sessions. The <code>Net::SSH.start</code> interface described above is simply a convenience for creating a new Session object explicitly.</p>
432
+
433
+
434
+ <pre>
435
+ require 'net/ssh'
436
+
437
+ Net::SSH::Session.new(
438
+ 'host', 'username', 'password',
439
+ :compression =&gt; "zlib"
440
+ ) do |session|
441
+ ...
442
+ end
443
+ </pre>
444
+ <p>Note that Net::SSH::Session#new accepts the same parameters as Net::SSH.start, and may also be called without a block.</p>
445
+ </div>
446
+
447
+
448
+
449
+
450
+ </div>
451
+
452
+ </td></tr>
453
+ </table>
454
+ </body>
455
+ </html>