net-ssh 0.6.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. data/doc/manual-html/chapter-1.html +59 -24
  2. data/doc/manual-html/chapter-2.html +116 -77
  3. data/doc/manual-html/chapter-3.html +80 -41
  4. data/doc/manual-html/chapter-4.html +111 -71
  5. data/doc/manual-html/chapter-5.html +267 -155
  6. data/doc/manual-html/chapter-6.html +211 -75
  7. data/doc/manual-html/chapter-7.html +331 -0
  8. data/doc/manual-html/index.html +39 -13
  9. data/doc/manual-html/{manual.css → stylesheets/manual.css} +81 -8
  10. data/doc/manual-html/stylesheets/ruby.css +17 -0
  11. data/doc/manual/chapter.erb +20 -0
  12. data/doc/manual/manual.rb +80 -9
  13. data/doc/manual/manual.yml +12 -2
  14. data/doc/manual/page.erb +1 -1
  15. data/doc/manual/parts/channels_callbacks.txt +11 -11
  16. data/doc/manual/parts/channels_loop.txt +6 -6
  17. data/doc/manual/parts/channels_open.txt +9 -9
  18. data/doc/manual/parts/exec_channels.txt +15 -15
  19. data/doc/manual/parts/exec_open.txt +17 -18
  20. data/doc/manual/parts/exec_popen3.txt +18 -18
  21. data/doc/manual/parts/forward_direct.txt +16 -16
  22. data/doc/manual/parts/forward_intro.txt +7 -7
  23. data/doc/manual/parts/forward_local.txt +9 -9
  24. data/doc/manual/parts/forward_remote.txt +9 -9
  25. data/doc/manual/parts/intro_getting.txt +11 -11
  26. data/doc/manual/parts/proxy_http.txt +27 -27
  27. data/doc/manual/parts/proxy_socks.txt +17 -17
  28. data/doc/manual/parts/session_key.txt +13 -14
  29. data/doc/manual/parts/session_options.txt +14 -14
  30. data/doc/manual/parts/session_session.txt +9 -9
  31. data/doc/manual/parts/session_start.txt +27 -27
  32. data/doc/manual/parts/shells_channels.txt +72 -0
  33. data/doc/manual/parts/shells_clients.txt +51 -0
  34. data/doc/manual/parts/shells_intro.txt +7 -0
  35. data/doc/manual/parts/shells_shell.txt +50 -0
  36. data/doc/manual/parts/shells_sync.txt +42 -0
  37. data/doc/manual/{manual.css → stylesheets/manual.css} +81 -8
  38. data/doc/manual/stylesheets/ruby.css +17 -0
  39. data/examples/channel-demo.rb +1 -1
  40. data/examples/port-forward.rb +1 -1
  41. data/examples/process-demo.rb +1 -1
  42. data/examples/remote-net-port-forward.rb +1 -1
  43. data/examples/remote-port-forward.rb +1 -1
  44. data/examples/shell-demo.rb +46 -0
  45. data/examples/ssh-client.rb +67 -0
  46. data/examples/sync-shell-demo.rb +69 -0
  47. data/examples/tail-demo.rb +1 -1
  48. data/lib/net/ssh.rb +1 -1
  49. data/lib/net/ssh/connection/channel.rb +61 -7
  50. data/lib/net/ssh/connection/constants.rb +1 -1
  51. data/lib/net/ssh/connection/driver.rb +61 -8
  52. data/lib/net/ssh/connection/services.rb +1 -1
  53. data/lib/net/ssh/connection/term.rb +1 -1
  54. data/lib/net/ssh/errors.rb +1 -1
  55. data/lib/net/ssh/proxy/errors.rb +1 -1
  56. data/lib/net/ssh/proxy/http.rb +1 -1
  57. data/lib/net/ssh/proxy/socks4.rb +1 -1
  58. data/lib/net/ssh/proxy/socks5.rb +1 -1
  59. data/lib/net/ssh/service/forward/driver.rb +1 -1
  60. data/lib/net/ssh/service/forward/local-network-handler.rb +1 -1
  61. data/lib/net/ssh/service/forward/remote-network-handler.rb +1 -1
  62. data/lib/net/ssh/service/forward/services.rb +1 -1
  63. data/lib/net/ssh/service/process/driver.rb +1 -1
  64. data/lib/net/ssh/service/process/open.rb +1 -1
  65. data/lib/net/ssh/service/process/popen3.rb +20 -2
  66. data/lib/net/ssh/service/process/services.rb +1 -1
  67. data/lib/net/ssh/service/services.rb +3 -1
  68. data/lib/net/ssh/service/shell/driver.rb +86 -0
  69. data/lib/net/ssh/service/shell/services.rb +54 -0
  70. data/lib/net/ssh/service/shell/shell.rb +213 -0
  71. data/lib/net/ssh/service/shell/sync.rb +114 -0
  72. data/lib/net/ssh/session.rb +9 -1
  73. data/lib/net/ssh/transport/algorithm-negotiator.rb +1 -1
  74. data/lib/net/ssh/transport/compress/compressor.rb +1 -1
  75. data/lib/net/ssh/transport/compress/decompressor.rb +1 -1
  76. data/lib/net/ssh/transport/compress/none-compressor.rb +1 -1
  77. data/lib/net/ssh/transport/compress/none-decompressor.rb +1 -1
  78. data/lib/net/ssh/transport/compress/services.rb +1 -1
  79. data/lib/net/ssh/transport/compress/zlib-compressor.rb +1 -1
  80. data/lib/net/ssh/transport/compress/zlib-decompressor.rb +1 -1
  81. data/lib/net/ssh/transport/constants.rb +1 -1
  82. data/lib/net/ssh/transport/errors.rb +1 -1
  83. data/lib/net/ssh/transport/identity-cipher.rb +1 -1
  84. data/lib/net/ssh/transport/kex/dh-gex.rb +1 -1
  85. data/lib/net/ssh/transport/kex/dh.rb +1 -1
  86. data/lib/net/ssh/transport/kex/services.rb +1 -1
  87. data/lib/net/ssh/transport/ossl/buffer-factory.rb +1 -1
  88. data/lib/net/ssh/transport/ossl/buffer.rb +1 -1
  89. data/lib/net/ssh/transport/ossl/cipher-factory.rb +1 -1
  90. data/lib/net/ssh/transport/ossl/digest-factory.rb +1 -1
  91. data/lib/net/ssh/transport/ossl/hmac-factory.rb +1 -1
  92. data/lib/net/ssh/transport/ossl/hmac/hmac.rb +1 -1
  93. data/lib/net/ssh/transport/ossl/hmac/md5-96.rb +1 -1
  94. data/lib/net/ssh/transport/ossl/hmac/md5.rb +1 -1
  95. data/lib/net/ssh/transport/ossl/hmac/none.rb +1 -1
  96. data/lib/net/ssh/transport/ossl/hmac/services.rb +1 -1
  97. data/lib/net/ssh/transport/ossl/hmac/sha1-96.rb +1 -1
  98. data/lib/net/ssh/transport/ossl/hmac/sha1.rb +1 -1
  99. data/lib/net/ssh/transport/ossl/key-factory.rb +5 -2
  100. data/lib/net/ssh/transport/ossl/services.rb +1 -1
  101. data/lib/net/ssh/transport/packet-stream.rb +1 -1
  102. data/lib/net/ssh/transport/services.rb +1 -1
  103. data/lib/net/ssh/transport/session.rb +10 -1
  104. data/lib/net/ssh/transport/version-negotiator.rb +1 -1
  105. data/lib/net/ssh/userauth/agent.rb +1 -1
  106. data/lib/net/ssh/userauth/constants.rb +1 -1
  107. data/lib/net/ssh/userauth/driver.rb +1 -1
  108. data/lib/net/ssh/userauth/methods/hostbased.rb +1 -1
  109. data/lib/net/ssh/userauth/methods/keyboard-interactive.rb +104 -0
  110. data/lib/net/ssh/userauth/methods/password.rb +1 -1
  111. data/lib/net/ssh/userauth/methods/publickey.rb +1 -1
  112. data/lib/net/ssh/userauth/methods/services.rb +28 -6
  113. data/lib/net/ssh/userauth/services.rb +8 -5
  114. data/lib/net/ssh/userauth/userkeys.rb +1 -1
  115. data/lib/net/ssh/util/buffer.rb +1 -1
  116. data/lib/net/ssh/util/openssl.rb +1 -1
  117. data/lib/net/ssh/util/prompter.rb +1 -1
  118. data/lib/net/ssh/version.rb +2 -2
  119. data/test/ALL-TESTS.rb +1 -1
  120. data/test/connection/tc_channel.rb +1 -1
  121. data/test/connection/tc_driver.rb +1 -1
  122. data/test/connection/tc_integration.rb +1 -1
  123. data/test/proxy/tc_http.rb +1 -1
  124. data/test/proxy/tc_socks4.rb +1 -1
  125. data/test/proxy/tc_socks5.rb +1 -1
  126. data/test/service/forward/tc_driver.rb +1 -1
  127. data/test/service/forward/tc_local_network_handler.rb +1 -1
  128. data/test/service/forward/tc_remote_network_handler.rb +1 -1
  129. data/test/service/process/tc_driver.rb +1 -1
  130. data/test/service/process/tc_integration.rb +1 -1
  131. data/test/service/process/tc_open.rb +1 -1
  132. data/test/service/process/tc_popen3.rb +13 -13
  133. data/test/tc_integration.rb +1 -1
  134. data/test/transport/compress/tc_none_compress.rb +1 -1
  135. data/test/transport/compress/tc_none_decompress.rb +1 -1
  136. data/test/transport/compress/tc_zlib_compress.rb +1 -1
  137. data/test/transport/compress/tc_zlib_decompress.rb +1 -1
  138. data/test/transport/kex/tc_dh.rb +2 -1
  139. data/test/transport/kex/tc_dh_gex.rb +1 -1
  140. data/test/transport/ossl/hmac/tc_hmac.rb +1 -1
  141. data/test/transport/ossl/hmac/tc_md5.rb +1 -1
  142. data/test/transport/ossl/hmac/tc_md5_96.rb +1 -1
  143. data/test/transport/ossl/hmac/tc_none.rb +1 -1
  144. data/test/transport/ossl/hmac/tc_sha1.rb +1 -1
  145. data/test/transport/ossl/hmac/tc_sha1_96.rb +1 -1
  146. data/test/transport/ossl/tc_buffer.rb +1 -1
  147. data/test/transport/ossl/tc_buffer_factory.rb +1 -1
  148. data/test/transport/ossl/tc_cipher_factory.rb +1 -1
  149. data/test/transport/ossl/tc_digest_factory.rb +1 -1
  150. data/test/transport/ossl/tc_hmac_factory.rb +1 -1
  151. data/test/transport/ossl/tc_key_factory.rb +1 -1
  152. data/test/transport/tc_algorithm_negotiator.rb +1 -1
  153. data/test/transport/tc_identity_cipher.rb +1 -1
  154. data/test/transport/tc_integration.rb +1 -1
  155. data/test/transport/tc_packet_stream.rb +1 -1
  156. data/test/transport/tc_session.rb +1 -1
  157. data/test/transport/tc_version_negotiator.rb +1 -1
  158. data/test/userauth/methods/tc_hostbased.rb +1 -1
  159. data/test/userauth/methods/tc_password.rb +1 -1
  160. data/test/userauth/methods/tc_publickey.rb +1 -1
  161. data/test/userauth/tc_agent.rb +1 -1
  162. data/test/userauth/tc_driver.rb +1 -1
  163. data/test/userauth/tc_integration.rb +15 -1
  164. data/test/userauth/tc_userkeys.rb +1 -1
  165. data/test/util/tc_buffer.rb +5 -5
  166. metadata +26 -6
@@ -1,7 +1,7 @@
1
1
  <html>
2
2
  <head>
3
3
  <title>Net::SSH Manual :: Chapter 1: Introduction</title>
4
- <link type="text/css" rel="stylesheet" href="manual.css" />
4
+ <link type="text/css" rel="stylesheet" href="stylesheets/manual.css" />
5
5
  </head>
6
6
 
7
7
  <body>
@@ -14,8 +14,8 @@
14
14
  </div>
15
15
  </td><td valign='middle' align='right'>
16
16
  <div class="info">
17
- Net::SSH Version: <strong>0.6.0</strong><br />
18
- Manual Last Updated: <strong>2004-12-02 05:13 GMT</strong>
17
+ Net::SSH Version: <strong>0.9.0</strong><br />
18
+ Manual Last Updated: <strong>2005-01-11 21:39 GMT</strong>
19
19
  </div>
20
20
  </td></tr>
21
21
  </table>
@@ -110,36 +110,56 @@
110
110
 
111
111
  <li>
112
112
  <a href="chapter-5.html">
113
- Port Forwarding
113
+ User Shells
114
114
  </a>
115
115
 
116
116
  <ol type="1">
117
117
 
118
118
  <li><a href="chapter-5.html#s1">Introduction</a></li>
119
119
 
120
- <li><a href="chapter-5.html#s2">Local-to-Remote</a></li>
120
+ <li><a href="chapter-5.html#s2">Using Channels</a></li>
121
121
 
122
- <li><a href="chapter-5.html#s3">Remote-to-Local</a></li>
122
+ <li><a href="chapter-5.html#s3">Shell Service</a></li>
123
123
 
124
- <li><a href="chapter-5.html#s4">Direct Channels</a></li>
124
+ <li><a href="chapter-5.html#s4">SyncShell Service</a></li>
125
125
 
126
- <li><a href="chapter-5.html#s5">Remote-to-Local Handlers</a></li>
126
+ <li><a href="chapter-5.html#s5">Terminal Clients</a></li>
127
127
 
128
128
  </ol>
129
129
  </li>
130
130
 
131
131
  <li>
132
132
  <a href="chapter-6.html">
133
- Using Proxies
133
+ Port Forwarding
134
134
  </a>
135
135
 
136
136
  <ol type="1">
137
137
 
138
138
  <li><a href="chapter-6.html#s1">Introduction</a></li>
139
139
 
140
- <li><a href="chapter-6.html#s2"><span class="caps">HTTP</span></a></li>
140
+ <li><a href="chapter-6.html#s2">Local-to-Remote</a></li>
141
+
142
+ <li><a href="chapter-6.html#s3">Remote-to-Local</a></li>
143
+
144
+ <li><a href="chapter-6.html#s4">Direct Channels</a></li>
145
+
146
+ <li><a href="chapter-6.html#s5">Remote-to-Local Handlers</a></li>
147
+
148
+ </ol>
149
+ </li>
150
+
151
+ <li>
152
+ <a href="chapter-7.html">
153
+ Using Proxies
154
+ </a>
155
+
156
+ <ol type="1">
157
+
158
+ <li><a href="chapter-7.html#s1">Introduction</a></li>
159
+
160
+ <li><a href="chapter-7.html#s2"><span class="caps">HTTP</span></a></li>
141
161
 
142
- <li><a href="chapter-6.html#s3"><span class="caps">SOCKS</span></a></li>
162
+ <li><a href="chapter-7.html#s3"><span class="caps">SOCKS</span></a></li>
143
163
 
144
164
  </ol>
145
165
  </li>
@@ -170,7 +190,15 @@
170
190
 
171
191
  <div id="content">
172
192
 
173
- <h1>1. Introduction</h1>
193
+ <div class="top"><div class="prevnext">
194
+
195
+ <a href="index.html">Up</a>
196
+
197
+ | <a href="chapter-2.html">Next (2. Starting a Session)</a>
198
+
199
+ </div></div>
200
+
201
+ <h1>1. Introduction</h1>
174
202
 
175
203
 
176
204
 
@@ -229,20 +257,20 @@
229
257
 
230
258
  <p>If you have <a href="http://rubygems.rubyforge.org">RubyGems</a> installed, installing Net::SSH is simple:</p>
231
259
 
260
+ <div class='figure'>
261
+ <span class='caption'>Using Rubygems to install Net::SSH [shell]</span>
262
+ <div class='body'><link rel='stylesheet' type='text/css' href='stylesheets/shell.css' /><div class='shell'><pre>gem install net-ssh</pre></div></div></div>
232
263
 
233
- <pre>
234
- gem install net-ssh
235
- </pre>
236
264
  <p>You still need to make sure you have a working version of Ruby&#8217;s OpenSSL module, but other than that, you should be good to go!</p>
237
265
 
238
266
  <h3>Using <a href="http://rpa-base.rubyforge.org">rpa-base</a></h3>
239
267
 
240
268
  <p>If you have <a href="http://rpa-base.rubyforge.org">rpa-base</a> installed:</p>
241
269
 
270
+ <div class='figure'>
271
+ <span class='caption'>Using RPA to install Net::SSH [shell]</span>
272
+ <div class='body'><link rel='stylesheet' type='text/css' href='stylesheets/shell.css' /><div class='shell'><pre>rpa install net-ssh</pre></div></div></div>
242
273
 
243
- <pre>
244
- rpa install net-ssh
245
- </pre>
246
274
  <p>As with the gem install, you still need to make sure you have a working version of Ruby&#8217;s OpenSSL module, but other than that, you should be good to go!</p>
247
275
 
248
276
  <h3>Doing it the hard way</h3>
@@ -251,12 +279,11 @@
251
279
 
252
280
  <p>Then, unpack the archive and run the <code>setup.rb</code> script:</p>
253
281
 
254
-
255
- <pre>
256
- ruby setup.rb config
257
- ruby setup.rb setup
258
- ruby setup.rb install
259
- </pre>
282
+ <div class='figure'>
283
+ <span class='caption'>Using setup.rb to install Net::SSH [shell]</span>
284
+ <div class='body'><link rel='stylesheet' type='text/css' href='stylesheets/shell.css' /><div class='shell'><pre>ruby setup.rb config
285
+ ruby setup.rb setup
286
+ ruby setup.rb install</pre></div></div></div>
260
287
  </div>
261
288
 
262
289
 
@@ -324,6 +351,14 @@
324
351
 
325
352
 
326
353
 
354
+ <div class="bottom"><div class="prevnext">
355
+
356
+ <a href="index.html">Up</a>
357
+
358
+ | <a href="chapter-2.html">Next (2. Starting a Session)</a>
359
+
360
+ </div></div>
361
+
327
362
 
328
363
  </div>
329
364
 
@@ -1,7 +1,7 @@
1
1
  <html>
2
2
  <head>
3
3
  <title>Net::SSH Manual :: Chapter 2: Starting a Session</title>
4
- <link type="text/css" rel="stylesheet" href="manual.css" />
4
+ <link type="text/css" rel="stylesheet" href="stylesheets/manual.css" />
5
5
  </head>
6
6
 
7
7
  <body>
@@ -14,8 +14,8 @@
14
14
  </div>
15
15
  </td><td valign='middle' align='right'>
16
16
  <div class="info">
17
- Net::SSH Version: <strong>0.6.0</strong><br />
18
- Manual Last Updated: <strong>2004-12-02 05:13 GMT</strong>
17
+ Net::SSH Version: <strong>0.9.0</strong><br />
18
+ Manual Last Updated: <strong>2005-01-11 21:39 GMT</strong>
19
19
  </div>
20
20
  </td></tr>
21
21
  </table>
@@ -110,36 +110,56 @@
110
110
 
111
111
  <li>
112
112
  <a href="chapter-5.html">
113
- Port Forwarding
113
+ User Shells
114
114
  </a>
115
115
 
116
116
  <ol type="1">
117
117
 
118
118
  <li><a href="chapter-5.html#s1">Introduction</a></li>
119
119
 
120
- <li><a href="chapter-5.html#s2">Local-to-Remote</a></li>
120
+ <li><a href="chapter-5.html#s2">Using Channels</a></li>
121
121
 
122
- <li><a href="chapter-5.html#s3">Remote-to-Local</a></li>
122
+ <li><a href="chapter-5.html#s3">Shell Service</a></li>
123
123
 
124
- <li><a href="chapter-5.html#s4">Direct Channels</a></li>
124
+ <li><a href="chapter-5.html#s4">SyncShell Service</a></li>
125
125
 
126
- <li><a href="chapter-5.html#s5">Remote-to-Local Handlers</a></li>
126
+ <li><a href="chapter-5.html#s5">Terminal Clients</a></li>
127
127
 
128
128
  </ol>
129
129
  </li>
130
130
 
131
131
  <li>
132
132
  <a href="chapter-6.html">
133
- Using Proxies
133
+ Port Forwarding
134
134
  </a>
135
135
 
136
136
  <ol type="1">
137
137
 
138
138
  <li><a href="chapter-6.html#s1">Introduction</a></li>
139
139
 
140
- <li><a href="chapter-6.html#s2"><span class="caps">HTTP</span></a></li>
140
+ <li><a href="chapter-6.html#s2">Local-to-Remote</a></li>
141
+
142
+ <li><a href="chapter-6.html#s3">Remote-to-Local</a></li>
143
+
144
+ <li><a href="chapter-6.html#s4">Direct Channels</a></li>
145
+
146
+ <li><a href="chapter-6.html#s5">Remote-to-Local Handlers</a></li>
147
+
148
+ </ol>
149
+ </li>
150
+
151
+ <li>
152
+ <a href="chapter-7.html">
153
+ Using Proxies
154
+ </a>
155
+
156
+ <ol type="1">
157
+
158
+ <li><a href="chapter-7.html#s1">Introduction</a></li>
141
159
 
142
- <li><a href="chapter-6.html#s3"><span class="caps">SOCKS</span></a></li>
160
+ <li><a href="chapter-7.html#s2"><span class="caps">HTTP</span></a></li>
161
+
162
+ <li><a href="chapter-7.html#s3"><span class="caps">SOCKS</span></a></li>
143
163
 
144
164
  </ol>
145
165
  </li>
@@ -170,7 +190,17 @@
170
190
 
171
191
  <div id="content">
172
192
 
173
- <h1>2. Starting a Session</h1>
193
+ <div class="top"><div class="prevnext">
194
+
195
+ <a href="chapter-1.html">Previous (1. Introduction)</a> |
196
+
197
+ <a href="index.html">Up</a>
198
+
199
+ | <a href="chapter-3.html">Next (3. Channels)</a>
200
+
201
+ </div></div>
202
+
203
+ <h1>2. Starting a Session</h1>
174
204
 
175
205
 
176
206
 
@@ -184,48 +214,48 @@
184
214
  <div class="section">
185
215
  <p>Before you can do anything with Net::SSH, you need to require the <code>net/ssh</code> module:</p>
186
216
 
217
+ <div class='figure'>
218
+ <span class='caption'>Requiring Net::SSH [ruby]</span>
219
+ <div class='body'><link rel='stylesheet' type='text/css' href='stylesheets/ruby.css' /><div class='ruby'><pre><span class="ident">require</span> <span class="punct">'</span><span class="string">net/ssh</span><span class="punct">'</span></pre></div></div></div>
187
220
 
188
- <pre>
189
- require 'net/ssh'
190
- </pre>
191
221
  <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
222
 
223
+ <div class='figure'>
224
+ <span class='caption'>Opening an SSH session [ruby]</span>
225
+ <div class='body'><table border='0' cellpadding='0' cellspacing='0'><tr><td class='lineno'>1<br />2<br />3<br /></td><td width='100%'><link rel='stylesheet' type='text/css' href='stylesheets/ruby.css' /><div class='ruby'><pre><span class="ident">session</span> <span class="punct">=</span> <span class="constant">Net</span><span class="punct">::</span><span class="constant">SSH</span><span class="punct">.</span><span class="ident">start</span><span class="punct">(</span> <span class="punct">'</span><span class="string">host</span><span class="punct">',</span> <span class="punct">'</span><span class="string">user</span><span class="punct">',</span> <span class="punct">'</span><span class="string">passwd</span><span class="punct">'</span> <span class="punct">)</span>
226
+ <span class="punct">...</span>
227
+ <span class="ident">session</span><span class="punct">.</span><span class="ident">close</span></pre></div></td></tr></table></div></div>
193
228
 
194
- <pre>
195
- session = Net::SSH.start( 'host', 'user', 'passwd' )
196
- ...
197
- session.close
198
- </pre>
199
229
  <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
230
 
231
+ <div class='figure'>
232
+ <span class='caption'>Opening a transactional SSH session [ruby]</span>
233
+ <div class='body'><table border='0' cellpadding='0' cellspacing='0'><tr><td class='lineno'>1<br />2<br />3<br /></td><td width='100%'><link rel='stylesheet' type='text/css' href='stylesheets/ruby.css' /><div class='ruby'><pre><span class="constant">Net</span><span class="punct">::</span><span class="constant">SSH</span><span class="punct">.</span><span class="ident">start</span><span class="punct">(</span> <span class="punct">'</span><span class="string">host</span><span class="punct">',</span> <span class="punct">'</span><span class="string">user</span><span class="punct">',</span> <span class="punct">'</span><span class="string">passwd</span><span class="punct">'</span> <span class="punct">)</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">session</span><span class="punct">|</span>
234
+ <span class="punct">...</span>
235
+ <span class="keyword">end</span></pre></div></td></tr></table></div></div>
201
236
 
202
- <pre>
203
- Net::SSH.start( 'host', 'user', 'passwd' ) do |session|
204
- ...
205
- end
206
- </pre>
207
237
  <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
238
 
239
+ <div class='figure'>
240
+ <span class='caption'>Specifying the SSH port [ruby]</span>
241
+ <div class='body'><table border='0' cellpadding='0' cellspacing='0'><tr><td class='lineno'>1<br />2<br />3<br /></td><td width='100%'><link rel='stylesheet' type='text/css' href='stylesheets/ruby.css' /><div class='ruby'><pre><span class="constant">Net</span><span class="punct">::</span><span class="constant">SSH</span><span class="punct">.</span><span class="ident">start</span><span class="punct">(</span> <span class="punct">'</span><span class="string">host</span><span class="punct">',</span> <span class="number">1234</span><span class="punct">,</span> <span class="punct">'</span><span class="string">user</span><span class="punct">',</span> <span class="punct">'</span><span class="string">passwd</span><span class="punct">'</span> <span class="punct">)</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">session</span><span class="punct">|</span>
242
+ <span class="punct">...</span>
243
+ <span class="keyword">end</span></pre></div></td></tr></table></div></div>
209
244
 
210
- <pre>
211
- Net::SSH.start( 'host', 1234, 'user', 'passwd' ) do |session|
212
- ...
213
- end
214
- </pre>
215
245
  <h3>Using Keyword Arguments</h3>
216
246
 
217
247
  <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
248
 
249
+ <div class='figure'>
250
+ <span class='caption'>Using keyword arguments [ruby]</span>
251
+ <div class='body'><table border='0' cellpadding='0' cellspacing='0'><tr><td class='lineno'>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></td><td width='100%'><link rel='stylesheet' type='text/css' href='stylesheets/ruby.css' /><div class='ruby'><pre><span class="constant">Net</span><span class="punct">::</span><span class="constant">SSH</span><span class="punct">.</span><span class="ident">start</span><span class="punct">(</span> <span class="punct">'</span><span class="string">host</span><span class="punct">',</span>
252
+ <span class="symbol">:password</span><span class="punct">=&gt;'</span><span class="string">passwd</span><span class="punct">',</span>
253
+ <span class="symbol">:port</span><span class="punct">=&gt;</span><span class="number">1234</span><span class="punct">,</span>
254
+ <span class="symbol">:username</span><span class="punct">=&gt;'</span><span class="string">user</span><span class="punct">',</span>
255
+ <span class="punct">...</span> <span class="punct">)</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">session</span><span class="punct">|</span>
256
+ <span class="punct">...</span>
257
+ <span class="keyword">end</span></pre></div></td></tr></table></div></div>
219
258
 
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
259
  <p>(More about the &#8220;<code>...</code>&#8221; stuff, later.)</p>
230
260
 
231
261
  <h3>Failed Authentication</h3>
@@ -261,10 +291,10 @@
261
291
 
262
292
  <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
293
 
294
+ <div class='figure'>
295
+ <span class='caption'>Generating an SSH key [shell]</span>
296
+ <div class='body'><link rel='stylesheet' type='text/css' href='stylesheets/shell.css' /><div class='shell'><pre>ssh-keygen -t dsa</pre></div></div></div>
264
297
 
265
- <pre>
266
- ssh-keygen -t dsa
267
- </pre>
268
298
  <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
299
 
270
300
  <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>
@@ -277,20 +307,20 @@
277
307
 
278
308
  <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
309
 
310
+ <div class='figure'>
311
+ <span class='caption'>SSH authentication using keys [ruby]</span>
312
+ <div class='body'><table border='0' cellpadding='0' cellspacing='0'><tr><td class='lineno'>1<br />2<br />3<br /></td><td width='100%'><link rel='stylesheet' type='text/css' href='stylesheets/ruby.css' /><div class='ruby'><pre><span class="constant">Net</span><span class="punct">::</span><span class="constant">SSH</span><span class="punct">.</span><span class="ident">start</span><span class="punct">(</span> <span class="punct">'</span><span class="string">host</span><span class="punct">',</span> <span class="punct">'</span><span class="string">user</span><span class="punct">'</span> <span class="punct">)</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">session</span><span class="punct">|</span>
313
+ <span class="punct">...</span>
314
+ <span class="keyword">end</span></pre></div></td></tr></table></div></div>
280
315
 
281
- <pre>
282
- Net::SSH.start( 'host', 'user' ) do |session|
283
- ...
284
- end
285
- </pre>
286
316
  <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
317
 
318
+ <div class='figure'>
319
+ <span class='caption'>Authentication with an implicit user name [ruby]</span>
320
+ <div class='body'><table border='0' cellpadding='0' cellspacing='0'><tr><td class='lineno'>1<br />2<br />3<br /></td><td width='100%'><link rel='stylesheet' type='text/css' href='stylesheets/ruby.css' /><div class='ruby'><pre><span class="constant">Net</span><span class="punct">::</span><span class="constant">SSH</span><span class="punct">.</span><span class="ident">start</span><span class="punct">(</span> <span class="punct">'</span><span class="string">host</span><span class="punct">'</span> <span class="punct">)</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">session</span><span class="punct">|</span>
321
+ <span class="punct">...</span>
322
+ <span class="keyword">end</span></pre></div></td></tr></table></div></div>
288
323
 
289
- <pre>
290
- Net::SSH.start( 'host' ) do |session|
291
- ...
292
- end
293
- </pre>
294
324
  <h3>Using keys with passphrases</h3>
295
325
 
296
326
  <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>
@@ -335,7 +365,7 @@
335
365
  </tr>
336
366
  <tr>
337
367
  <td style="vertical-align:top;text-align:center;"><code>:auth_methods</code> </td>
338
- <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>
368
+ <td> This is the list of authorization methods to try. It defaults to &#8220;publickey&#8221;, &#8220;hostbased&#8221;, &#8220;password&#8221;, and &#8220;keyboard-interactive&#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>
339
369
  </tr>
340
370
  <tr>
341
371
  <td style="vertical-align:top;text-align:center;"><code>:compression</code> </td>
@@ -403,21 +433,20 @@
403
433
 
404
434
  <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>
405
435
 
406
-
407
- <pre>
408
- require 'net/ssh'
409
- require 'logger'
410
-
411
- Net::SSH.start(
412
- 'host', 'user',
413
- :host_key =&gt; "ssh-rsa",
414
- :encryption =&gt; "blowfish-cbc",
415
- :keys =&gt; [ "/tmp/temporary-key" ],
416
- :compression =&gt; "zlib"
417
- ) do |session|
418
- ...
419
- end
420
- </pre>
436
+ <div class='figure'>
437
+ <span class='caption'>Specifying options when connecting [ruby]</span>
438
+ <div class='body'><table border='0' cellpadding='0' cellspacing='0'><tr><td class='lineno'>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></td><td width='100%'><link rel='stylesheet' type='text/css' href='stylesheets/ruby.css' /><div class='ruby'><pre><span class="ident">require</span> <span class="punct">'</span><span class="string">net/ssh</span><span class="punct">'</span>
439
+ <span class="ident">require</span> <span class="punct">'</span><span class="string">logger</span><span class="punct">'</span>
440
+
441
+ <span class="constant">Net</span><span class="punct">::</span><span class="constant">SSH</span><span class="punct">.</span><span class="ident">start</span><span class="punct">(</span>
442
+ <span class="punct">'</span><span class="string">host</span><span class="punct">',</span> <span class="punct">'</span><span class="string">user</span><span class="punct">',</span>
443
+ <span class="symbol">:host_key</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">ssh-rsa</span><span class="punct">&quot;,</span>
444
+ <span class="symbol">:encryption</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">blowfish-cbc</span><span class="punct">&quot;,</span>
445
+ <span class="symbol">:keys</span> <span class="punct">=&gt;</span> <span class="punct">[</span> <span class="punct">&quot;</span><span class="string">/tmp/temporary-key</span><span class="punct">&quot;</span> <span class="punct">],</span>
446
+ <span class="symbol">:compression</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">zlib</span><span class="punct">&quot;</span>
447
+ <span class="punct">)</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">session</span><span class="punct">|</span>
448
+ <span class="punct">...</span>
449
+ <span class="keyword">end</span></pre></div></td></tr></table></div></div>
421
450
  </div>
422
451
 
423
452
 
@@ -432,22 +461,32 @@
432
461
  <div class="section">
433
462
  <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>
434
463
 
464
+ <div class='figure'>
465
+ <span class='caption'>Using Net::SSH::Session [ruby]</span>
466
+ <div class='body'><table border='0' cellpadding='0' cellspacing='0'><tr><td class='lineno'>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></td><td width='100%'><link rel='stylesheet' type='text/css' href='stylesheets/ruby.css' /><div class='ruby'><pre><span class="ident">require</span> <span class="punct">'</span><span class="string">net/ssh</span><span class="punct">'</span>
435
467
 
436
- <pre>
437
- require 'net/ssh'
468
+ <span class="constant">Net</span><span class="punct">::</span><span class="constant">SSH</span><span class="punct">::</span><span class="constant">Session</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span>
469
+ <span class="punct">'</span><span class="string">host</span><span class="punct">',</span> <span class="punct">'</span><span class="string">username</span><span class="punct">',</span> <span class="punct">'</span><span class="string">password</span><span class="punct">',</span>
470
+ <span class="symbol">:compression</span> <span class="punct">=&gt;</span> <span class="punct">&quot;</span><span class="string">zlib</span><span class="punct">&quot;</span>
471
+ <span class="punct">)</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">session</span><span class="punct">|</span>
472
+ <span class="punct">...</span>
473
+ <span class="keyword">end</span></pre></div></td></tr></table></div></div>
438
474
 
439
- Net::SSH::Session.new(
440
- 'host', 'username', 'password',
441
- :compression =&gt; "zlib"
442
- ) do |session|
443
- ...
444
- end
445
- </pre>
446
475
  <p>Note that Net::SSH::Session#new accepts the same parameters as Net::SSH.start, and may also be called without a block.</p>
447
476
  </div>
448
477
 
449
478
 
450
479
 
480
+ <div class="bottom"><div class="prevnext">
481
+
482
+ <a href="chapter-1.html">Previous (1. Introduction)</a> |
483
+
484
+ <a href="index.html">Up</a>
485
+
486
+ | <a href="chapter-3.html">Next (3. Channels)</a>
487
+
488
+ </div></div>
489
+
451
490
 
452
491
  </div>
453
492