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
- <title>Net::SSH Manual :: Chapter 6: Using Proxies</title>
4
- <link type="text/css" rel="stylesheet" href="manual.css" />
3
+ <title>Net::SSH Manual :: Chapter 6: Port Forwarding</title>
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><strong>
132
132
  <a href="chapter-6.html">
133
- Using Proxies
133
+ Port Forwarding
134
134
  </a>
135
135
  </strong> <big>&larr;</big>
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,17 @@
170
190
 
171
191
  <div id="content">
172
192
 
173
- <h1>6. Using Proxies</h1>
193
+ <div class="top"><div class="prevnext">
194
+
195
+ <a href="chapter-5.html">Previous (5. User Shells)</a> |
196
+
197
+ <a href="index.html">Up</a>
198
+
199
+ | <a href="chapter-7.html">Next (7. Using Proxies)</a>
200
+
201
+ </div></div>
202
+
203
+ <h1>6. Port Forwarding</h1>
174
204
 
175
205
 
176
206
 
@@ -182,111 +212,217 @@
182
212
 
183
213
 
184
214
  <div class="section">
185
- <p>Many times, you may find yourself behind a firewall, unable to <span class="caps">SSH</span> out. In such instances, you can often take advantage of your existing proxies to tunnel an <span class="caps">SSH</span> connection through your firewall.</p>
215
+ <p>Port forwarding is a feature of the <span class="caps">SSH</span> protocol that allows you to specify a port on one of the hosts, and have network connections on that port forwarded to a port on a different host, using the <span class="caps">SSH</span> connection as a proxy. There are basically two ways to use this forwarding:</p>
216
+ <ol>
217
+ <li>A port on the local host is forwarded via the remote host to another machine. Any connection to the specified port will cause all subsequent data to be sent over the connection to the remote host, where it will then be forwarded to the requested destination host.</li>
218
+ <li>A port on the remote host is forwarded over the connection to the local host, and from there to (potentially) some other remote destination. Any connection to the specified port on the remote host is forwarded over the connection to the local host, which then makes a connection to the specified remote destination and sends the data there.</li>
219
+ </ol>
220
+
221
+ <p>All port forwarding in the Net::SSH library is managed by the <code>#forward</code> service. Just invoke methods on that service to set up any of various port forwarding configurations.</p>
222
+
223
+ <div class='figure'>
224
+ <span class='caption'>Accessing the #forward service [ruby]</span>
225
+ <div class='body'><table border='0' cellpadding='0' cellspacing='0'><tr><td class='lineno'>1<br />2<br />3<br />4<br />5<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>
226
+ <span class="ident">forward</span> <span class="punct">=</span> <span class="ident">session</span><span class="punct">.</span><span class="ident">forward</span>
227
+ <span class="punct">...</span>
228
+ <span class="ident">session</span><span class="punct">.</span><span class="ident">loop</span>
229
+ <span class="keyword">end</span></pre></div></td></tr></table></div></div>
230
+
231
+ <p>You can define any number of forwards before invoking the main loop, in which case all of those forwards will be handled transparently (and silently) in parallel, over the same connection. (Isn&#8217;t <span class="caps">SSH</span> lovely?)</p>
232
+
233
+ <p>Naturally, you can also have remote processes, <span class="caps">SFTP</span> sessions, and more all working at the same time on the connection.</p>
186
234
  </div>
187
235
 
188
236
 
189
237
 
190
238
  <h2>
191
239
  <a name="s2"></a>
192
- 6.2. <span class="caps">HTTP</span>
240
+ 6.2. Local-to-Remote
193
241
  </h2>
194
242
 
195
243
 
196
244
 
197
245
  <div class="section">
198
- <p>If you have an <span class="caps">HTTP</span> proxy running, you may be able to use it to your advantage. The following snippet demonstrates how to tunnel an <span class="caps">SSH</span> connection through an <span class="caps">HTTP</span> proxy:</p>
199
-
246
+ <p>Forwarding a local connection to a remote destination is simply a matter of invoking the <code>#local</code> method of the <code>#forward</code> service. The simplest version of the method just takes three parameters: the local port to listen on, and the remote host and port to forward the connection to:</p>
200
247
 
201
- <pre>
202
- require 'net/ssh'
203
- require 'net/ssh/proxy/http'
248
+ <div class='figure'>
249
+ <span class='caption'>Forwarding a local port [ruby]</span>
250
+ <div class='body'><table border='0' cellpadding='0' cellspacing='0'><tr><td class='lineno'>1<br />2<br />3<br />4<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>
251
+ <span class="ident">session</span><span class="punct">.</span><span class="ident">forward</span><span class="punct">.</span><span class="ident">local</span><span class="punct">(</span> <span class="number">1234</span><span class="punct">,</span> <span class="punct">'</span><span class="string">www.google.com</span><span class="punct">',</span> <span class="number">80</span> <span class="punct">)</span>
252
+ <span class="ident">session</span><span class="punct">.</span><span class="ident">loop</span>
253
+ <span class="keyword">end</span></pre></div></td></tr></table></div></div>
204
254
 
205
- proxy_host = 'my.proxy.com'
206
- proxy_port = 8080
207
- proxy = Net::SSH::Proxy::HTTP.new( proxy_host, proxy_port )
255
+ <p>In the above example, then, any connection received on port 1234 will be forwarded to port 80 on &#8220;www.google.com&#8221;. This means that if you were to point a browser at &#8220;http://localhost:1234&#8221;, it would pull up <a href="http://www.google.com">Google</a>.</p>
208
256
 
209
- Net::SSH.start( 'host', :proxy =&gt; proxy ) do |session|
210
- ...
211
- end
212
- </pre>
213
- <p>As you can see, you first create an instance of the proxy you want to use. (This flexibility allows for other proxy types to be supported, although at present only <span class="caps">HTTP</span> and <span class="caps">SOCKS</span> are available.)</p>
257
+ <p>By default, only connections <em>from the local host</em> are accepted. This is because the default bind address is 127.0.0.1. You can specify any bind address you want (including 0.0.0.0 to allow connections from anywhere) by specifying that address as the first parameter to <code>#local</code>, with the local port number immediately following.</p>
214
258
 
215
- <p>Once you&#8217;ve created your proxy, you just start your <span class="caps">SSH</span> session, as usual, except you also pass a <code>:proxy</code> option. The proxy will then be used to obtain a connection to the remote host.</p>
216
-
217
- <p>Note: If your proxy does not allow connects to be made to other hosts on port 22, then you&#8217;ll have to do some magic to allow <span class="caps">SSH</span> connections on your remote host on ports other than 22. Port forwarding on that remote host (from itself, to itself), can help you there.</p>
218
-
219
- <p>For instance, if your proxy disallows connections to any port except (say) 443, you could run the following command on the remote host:</p>
259
+ <div class='figure'>
260
+ <span class='caption'>Specifying the bind address when forwarding a local port [ruby]</span>
261
+ <div class='body'><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="ident">forward</span><span class="punct">.</span><span class="ident">local</span><span class="punct">(</span> <span class="punct">'</span><span class="string">0.0.0.0</span><span class="punct">',</span> <span class="number">1234</span><span class="punct">,</span> <span class="punct">'</span><span class="string">www.google.com</span><span class="punct">',</span> <span class="number">80</span> <span class="punct">)</span></pre></div></div></div>
220
262
 
263
+ <p>In this configuration, anyone from anywhere can connect to your machine on port 1234 and be forwarded to Google.</p>
264
+ </div>
221
265
 
222
- <pre>
223
- ssh -gL 443:localhost:22 localhost
224
- </pre>
225
- <p>Then, as long as that command is running, port 443 will always be forwarded to port 22. Naturally, this means that you must run this command while you have access to the box; if you can&#8217;t access that machine in the first place (ie, because you&#8217;re behind a firewall), then it does you no good.</p>
226
266
 
227
- <h3>Proxy Authentication</h3>
228
267
 
229
- <p>Some proxies require authentication. Net::SSH supports these proxies as well. If you specify the user name either as a <code>:user</code> option to the <span class="caps">HTTP</span> proxy constructor, or in the <code>HTTP_PROXY_USER</code> or <code>CONNECT_USER</code> environment variables, that name will be used to authenticate with the proxy. Likewise, the password may be given either via the <code>:password</code> constructor option, or via the <code>HTTP_PROXY_PASSWORD</code> or <code>CONNECT_PASSWORD</code> environment variables.</p>
268
+ <h2>
269
+ <a name="s3"></a>
270
+ 6.3. Remote-to-Local
271
+ </h2>
230
272
 
273
+
231
274
 
232
- <pre>
233
- require 'net/ssh'
234
- require 'net/ssh/proxy/http'
275
+ <div class="section">
276
+ <p>Forwarding remote connections to the local host is also straightforward; simply call the <code>#remote_to</code> method of the <code>#forward</code> service. This takes three (or four) parameters: the local port and host to be forwarded to (in that order), and the remote port to listen on. The fourth parameter is optional, and is the bind address on the remote machine; this defaults to &#8220;127.0.0.1&#8221;.</p>
235
277
 
236
- proxy_host = 'my.proxy.com'
237
- proxy_port = 8080
238
- proxy_user = 'my-name'
239
- proxy_password = 'my-password'
278
+ <div class='figure'>
279
+ <span class='caption'>Forwarding a remote port [ruby]</span>
280
+ <div class='body'><table border='0' cellpadding='0' cellspacing='0'><tr><td class='lineno'>1<br />2<br />3<br />4<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>
281
+ <span class="ident">session</span><span class="punct">.</span><span class="ident">forward</span><span class="punct">.</span><span class="ident">remote_to</span><span class="punct">(</span> <span class="number">80</span><span class="punct">,</span> <span class="punct">'</span><span class="string">www.google.com</span><span class="punct">',</span> <span class="number">1234</span> <span class="punct">)</span>
282
+ <span class="ident">session</span><span class="punct">.</span><span class="ident">loop</span>
283
+ <span class="keyword">end</span></pre></div></td></tr></table></div></div>
240
284
 
241
- proxy = Net::SSH::Proxy::HTTP.new( proxy_host, proxy_port,
242
- :user =&gt; proxy_user,
243
- :password =&gt; proxy_password )
285
+ <p>The above example causes any connection on port 1234 of the remote machine (<em>from</em> the remote machine) to be forwarded via the local host to port 80 at www.google.com. To make things a bit more open, you could specify a bind address of 0.0.0.0:</p>
244
286
 
245
- Net::SSH.start( 'host', :proxy =&gt; proxy ) do |session|
246
- ...
247
- end
248
- </pre>
249
- <p>Note that currently, only basic authentication is supported; in the future, digest authentication may be added for proxies that support it.</p>
287
+ <div class='figure'>
288
+ <span class='caption'>Specifying the bind address when forwarding a remote port [ruby]</span>
289
+ <div class='body'><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="ident">forward</span><span class="punct">.</span><span class="ident">remote_to</span><span class="punct">(</span> <span class="number">80</span><span class="punct">,</span> <span class="punct">'</span><span class="string">www.google.com</span><span class="punct">',</span> <span class="number">1234</span><span class="punct">,</span> <span class="punct">'</span><span class="string">0.0.0.0</span><span class="punct">'</span> <span class="punct">)</span></pre></div></div></div>
250
290
  </div>
251
291
 
252
292
 
253
293
 
254
294
  <h2>
255
- <a name="s3"></a>
256
- 6.3. <span class="caps">SOCKS</span>
295
+ <a name="s4"></a>
296
+ 6.4. Direct Channels
257
297
  </h2>
258
298
 
259
299
 
260
300
 
261
301
  <div class="section">
262
- <p>In addition to the <span class="caps">HTTP</span> proxy, Net::SSH also supports <span class="caps">SOCKS</span> proxies (both versions 4 and 5). Their usage is almost identical to the <span class="caps">HTTP</span> version (except <span class="caps">SOCKS4</span> does not use passwords, just user names):</p>
263
-
302
+ <p>Sometimes it might be nice to programmatically simulate a network connection on a local port and have it forwarded to the remote host. You can do this by means of the <code>#direct_channel</code> method.</p>
303
+
304
+ <p>The <code>#direct_channel</code> method looks similar to <code>#local</code>: the first three parameters are the local port to simulate the connection from, and the remote host and port that the connection should be forwarded to. The fourth parameter, however, is a <em>handler</em>, an object that is used as a callback for a variety of different events.</p>
305
+
306
+ <p>The handler for the <code>#direct_channel</code> method may implement any of the following callbacks (all are optional, though you probably want to implement at least one or two of them):</p>
307
+
308
+ <table class="list">
309
+ <tr>
310
+ <th>Callback </th>
311
+ <th>Description </th>
312
+ </tr>
313
+ <tr>
314
+ <td style="vertical-align:top;text-align:center;"><code>confirm</code> </td>
315
+ <td> This is invoked when the channel has been opened and the remote host has confirmed it. This accepts four parameters: the channel itself, the local port, remote host, and remote port. (In this way, the same handler may be used for multiple forward requests.)</td>
316
+ </tr>
317
+ <tr>
318
+ <td style="vertical-align:top;text-align:center;"><code>process</code> </td>
319
+ <td> After the channel has been confirmed, this is invoked, to process the channel. This callback will be invoked in a new Thread, so that if your handler needs to listen to a socket and then send data received from it over the channel, it can do so without blocking the main loop. The callback accepts a single parameter, the channel handle itself.</td>
320
+ </tr>
321
+ <tr>
322
+ <td style="vertical-align:top;text-align:center;"><code>on_close</code> </td>
323
+ <td> This is called when the channel over which this forwarded connection is being processed has been closed. The callback accepts a single parameter, the channel itself.</td>
324
+ </tr>
325
+ <tr>
326
+ <td style="vertical-align:top;text-align:center;"><code>on_eof</code> </td>
327
+ <td> When the remote machine indicates it will send no more data, this callback will be invoked. It accepts a single parameter, the channel itself.</td>
328
+ </tr>
329
+ <tr>
330
+ <td style="vertical-align:top;text-align:center;"><code>on_receive</code> </td>
331
+ <td> This is invoked when data is received from the remote machine. It accepts two parameters: the channel handle, and the data that was received.</td>
332
+ </tr>
333
+ </table>
334
+
335
+
336
+
337
+ <p>For example, the following example pretends to be a client that has connected to the local host on a forwarded port:</p>
338
+
339
+ <div class='figure'>
340
+ <span class='caption'>Using a handler object to mimic a forwarded port [ruby]</span>
341
+ <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 />13<br />14<br />15<br />16<br />17<br /></td><td width='100%'><link rel='stylesheet' type='text/css' href='stylesheets/ruby.css' /><div class='ruby'><pre><span class="keyword">class </span><span class="class">Handler</span>
342
+ <span class="keyword">def </span><span class="method">on_receive</span><span class="punct">(</span> <span class="ident">channel</span><span class="punct">,</span> <span class="ident">data</span> <span class="punct">)</span>
343
+ <span class="ident">puts</span> <span class="punct">&quot;</span><span class="string">got data: </span><span class="expr">#{data.inspect}</span><span class="punct">&quot;</span>
344
+ <span class="ident">channel</span><span class="punct">.</span><span class="ident">send_data</span> <span class="punct">&quot;</span><span class="string">subsequent request</span><span class="punct">&quot;</span>
345
+ <span class="keyword">end</span>
346
+
347
+ <span class="keyword">def </span><span class="method">process</span><span class="punct">(</span> <span class="ident">channel</span> <span class="punct">)</span>
348
+ <span class="ident">channel</span><span class="punct">.</span><span class="ident">send_data</span> <span class="punct">&quot;</span><span class="string">initial request</span><span class="punct">&quot;</span>
349
+ <span class="keyword">end</span>
350
+ <span class="keyword">end</span>
351
+
352
+ <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>
353
+ <span class="ident">session</span><span class="punct">.</span><span class="ident">forward</span><span class="punct">.</span><span class="ident">direct_channel</span><span class="punct">(</span> <span class="number">1234</span><span class="punct">,</span> <span class="punct">'</span><span class="string">somewhere.else.net</span><span class="punct">',</span>
354
+ <span class="number">4321</span><span class="punct">,</span> <span class="constant">Handler</span><span class="punct">.</span><span class="ident">new</span> <span class="punct">)</span>
355
+
356
+ <span class="ident">session</span><span class="punct">.</span><span class="ident">loop</span>
357
+ <span class="keyword">end</span></pre></div></td></tr></table></div></div>
358
+
359
+ <p>The local port number for <code>#direct_channel</code> has no real purpose, other than to report to the <span class="caps">SSH</span> server that the &#8220;virtual&#8221; connection occurred on that port.</p>
360
+ </div>
264
361
 
265
- <pre>
266
- require 'net/ssh'
267
- require 'net/ssh/proxy/socks4'
268
- require 'net/ssh/proxy/socks5'
269
362
 
270
- proxy_host = 'my.proxy.com'
271
- proxy_port = 1080
272
- proxy_user = 'my-name'
273
- proxy_password = 'my-password'
274
363
 
275
- socks4 = Net::SSH::Proxy::SOCKS4.new( proxy_host, proxy_port,
276
- :user =&gt; proxy_user )
364
+ <h2>
365
+ <a name="s5"></a>
366
+ 6.5. Remote-to-Local Handlers
367
+ </h2>
277
368
 
278
- socks5 = Net::SSH::Proxy::SOCKS5.new( proxy_host, proxy_port,
279
- :user =&gt; proxy_user,
280
- :password =&gt; proxy_password)
369
+
281
370
 
282
- Net::SSH.start( 'host', :proxy =&gt; socks4 ) do |session|
283
- ...
284
- end
285
- </pre>
371
+ <div class="section">
372
+ <p>You can use handlers going in the other direction, too. If you want to programmatically process forwarded data from a remote host, you can use the <code>#remote</code> method. This takes two parameters, with an optional third parameter. The two required parameters are the handler to use, and the remote port that should be listened to. The optional parameter is the remote bind address, which defaults to &#8216;127.0.0.1&#8217;.</p>
373
+
374
+ <p>(Incidentally, if the port is 0, a new port will be allocated for you automatically by the server.)</p>
375
+
376
+ <p>Whenever connections are received on the remote port, they will be forwarded to the handler, which may implement the following callbacks:</p>
377
+
378
+ <table class="list">
379
+ <tr>
380
+ <th>Callback </th>
381
+ <th>Description </th>
382
+ </tr>
383
+ <tr>
384
+ <td style="vertical-align:top;text-align:center;"><code>error</code> </td>
385
+ <td> This is invoked if the forward could not be initiated. It accepts a single parameter, which is the error message. </td>
386
+ </tr>
387
+ <tr>
388
+ <td style="vertical-align:top;text-align:center;"><code>on_close</code> </td>
389
+ <td> This is invoked when the channel that was assigned to process this forwarded connection has been closed. The callback takes one parameter: the channel itself. </td>
390
+ </tr>
391
+ <tr>
392
+ <td style="vertical-align:top;text-align:center;"><code>on_eof</code> </td>
393
+ <td> This is invoked when the remote end of the connection has promised not to send any more data. The local end of the channel may continue to send data, however. This callback takes on parameter: the channel itself.</td>
394
+ </tr>
395
+ <tr>
396
+ <td style="vertical-align:top;text-align:center;"><code>on_open</code> </td>
397
+ <td> This is invoked when a new connection is received over the forwarded channel. It accepts five parameters: the channel object, the connected address, the connected port, the originator address, and the originator port. </td>
398
+ </tr>
399
+ <tr>
400
+ <td style="vertical-align:top;text-align:center;"><code>on_receive</code> </td>
401
+ <td> This is invoked when data is received over the channel from the remote connection. It accepts two parameters: the channel object, and the data that was received. </td>
402
+ </tr>
403
+ <tr>
404
+ <td style="vertical-align:top;text-align:center;"><code>setup</code> </td>
405
+ <td> This is invoked immediately after the forward request has been acknowledged as successful. It accepts a single parameter, which is the port that was assigned to this forward. If the port parameter to <code>#remote</code> was not 0, then that same value will be passed to the callback. Otherwise, the newly allocated port number will be passed to the callback. </td>
406
+ </tr>
407
+ </table>
408
+
409
+
410
+
411
+ <p>Note that the <code>on_receive</code> handler is required&#8212;all other callbacks may remain unimplemented by the handler.</p>
286
412
  </div>
287
413
 
288
414
 
289
415
 
416
+ <div class="bottom"><div class="prevnext">
417
+
418
+ <a href="chapter-5.html">Previous (5. User Shells)</a> |
419
+
420
+ <a href="index.html">Up</a>
421
+
422
+ | <a href="chapter-7.html">Next (7. Using Proxies)</a>
423
+
424
+ </div></div>
425
+
290
426
 
291
427
  </div>
292
428
 
@@ -0,0 +1,331 @@
1
+ <html>
2
+ <head>
3
+ <title>Net::SSH Manual :: Chapter 7: Using Proxies</title>
4
+ <link type="text/css" rel="stylesheet" href="stylesheets/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.9.0</strong><br />
18
+ Manual Last Updated: <strong>2005-01-11 21:39 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>
56
+ <a href="chapter-2.html">
57
+ Starting a Session
58
+ </a>
59
+
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
+ User Shells
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">Using Channels</a></li>
121
+
122
+ <li><a href="chapter-5.html#s3">Shell Service</a></li>
123
+
124
+ <li><a href="chapter-5.html#s4">SyncShell Service</a></li>
125
+
126
+ <li><a href="chapter-5.html#s5">Terminal Clients</a></li>
127
+
128
+ </ol>
129
+ </li>
130
+
131
+ <li>
132
+ <a href="chapter-6.html">
133
+ Port Forwarding
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">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><strong>
152
+ <a href="chapter-7.html">
153
+ Using Proxies
154
+ </a>
155
+ </strong> <big>&larr;</big>
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>
161
+
162
+ <li><a href="chapter-7.html#s3"><span class="caps">SOCKS</span></a></li>
163
+
164
+ </ol>
165
+ </li>
166
+
167
+ </ol>
168
+
169
+ <h2>Other Documentation</h2>
170
+
171
+ <ul>
172
+ <li><a href="http://net-ssh.rubyforge.org/api/index.html">Net::SSH API</a></li>
173
+ <li><a href="http://rubyforge.org/tracker/?atid=1842&group_id=274&func=browse">Net::SSH FAQ</a></li>
174
+ </ul>
175
+
176
+ <h2>Tutorials</h2>
177
+ <ol>
178
+
179
+ </ol>
180
+
181
+ <p align="center"><strong>More To Come...</strong></p>
182
+
183
+ <div class="license">
184
+ <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 />
185
+ This manual is licensed under a <a href="http://creativecommons.org/licenses/by-sa/2.0/">Creative Commons License</a>.
186
+ </div>
187
+ </div>
188
+
189
+ </td><td valign='top' width="100%">
190
+
191
+ <div id="content">
192
+
193
+ <div class="top"><div class="prevnext">
194
+
195
+ <a href="chapter-6.html">Previous (6. Port Forwarding)</a> |
196
+
197
+ <a href="index.html">Up</a>
198
+
199
+ </div></div>
200
+
201
+ <h1>7. Using Proxies</h1>
202
+
203
+
204
+
205
+ <h2>
206
+ <a name="s1"></a>
207
+ 7.1. Introduction
208
+ </h2>
209
+
210
+
211
+
212
+ <div class="section">
213
+ <p>Many times, you may find yourself behind a firewall, unable to <span class="caps">SSH</span> out. In such instances, you can often take advantage of your existing proxies to tunnel an <span class="caps">SSH</span> connection through your firewall.</p>
214
+ </div>
215
+
216
+
217
+
218
+ <h2>
219
+ <a name="s2"></a>
220
+ 7.2. <span class="caps">HTTP</span>
221
+ </h2>
222
+
223
+
224
+
225
+ <div class="section">
226
+ <p>If you have an <span class="caps">HTTP</span> proxy running, you may be able to use it to your advantage. The following snippet demonstrates how to tunnel an <span class="caps">SSH</span> connection through an <span class="caps">HTTP</span> proxy:</p>
227
+
228
+ <div class='figure'>
229
+ <span class='caption'>Tunnelling an SSH connection over HTTP [ruby]</span>
230
+ <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 /></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>
231
+ <span class="ident">require</span> <span class="punct">'</span><span class="string">net/ssh/proxy/http</span><span class="punct">'</span>
232
+
233
+ <span class="ident">proxy_host</span> <span class="punct">=</span> <span class="punct">'</span><span class="string">my.proxy.com</span><span class="punct">'</span>
234
+ <span class="ident">proxy_port</span> <span class="punct">=</span> <span class="number">8080</span>
235
+ <span class="ident">proxy</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="constant">Proxy</span><span class="punct">::</span><span class="constant">HTTP</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span> <span class="ident">proxy_host</span><span class="punct">,</span> <span class="ident">proxy_port</span> <span class="punct">)</span>
236
+
237
+ <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="symbol">:proxy</span> <span class="punct">=&gt;</span> <span class="ident">proxy</span> <span class="punct">)</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">session</span><span class="punct">|</span>
238
+ <span class="punct">...</span>
239
+ <span class="keyword">end</span></pre></div></td></tr></table></div></div>
240
+
241
+ <p>As you can see, you first create an instance of the proxy you want to use. (This flexibility allows for other proxy types to be supported, although at present only <span class="caps">HTTP</span> and <span class="caps">SOCKS</span> are available.)</p>
242
+
243
+ <p>Once you&#8217;ve created your proxy, you just start your <span class="caps">SSH</span> session, as usual, except you also pass a <code>:proxy</code> option. The proxy will then be used to obtain a connection to the remote host.</p>
244
+
245
+ <p>Note: If your proxy does not allow connects to be made to other hosts on port 22, then you&#8217;ll have to do some magic to allow <span class="caps">SSH</span> connections on your remote host on ports other than 22. Port forwarding on that remote host (from itself, to itself), can help you there.</p>
246
+
247
+ <p>For instance, if your proxy disallows connections to any port except (say) 443, you could run the following command on the remote host:</p>
248
+
249
+ <div class='figure'>
250
+ <span class='caption'>Forwarding a port using the ssh command [shell]</span>
251
+ <div class='body'><link rel='stylesheet' type='text/css' href='stylesheets/shell.css' /><div class='shell'><pre>ssh -gL 443:localhost:22 localhost</pre></div></div></div>
252
+
253
+ <p>Then, as long as that command is running, port 443 will always be forwarded to port 22. Naturally, this means that you must run this command while you have access to the box; if you can&#8217;t access that machine in the first place (ie, because you&#8217;re behind a firewall), then it does you no good.</p>
254
+
255
+ <h3>Proxy Authentication</h3>
256
+
257
+ <p>Some proxies require authentication. Net::SSH supports these proxies as well. If you specify the user name either as a <code>:user</code> option to the <span class="caps">HTTP</span> proxy constructor, or in the <code>HTTP_PROXY_USER</code> or <code>CONNECT_USER</code> environment variables, that name will be used to authenticate with the proxy. Likewise, the password may be given either via the <code>:password</code> constructor option, or via the <code>HTTP_PROXY_PASSWORD</code> or <code>CONNECT_PASSWORD</code> environment variables.</p>
258
+
259
+ <div class='figure'>
260
+ <span class='caption'>Using HTTP proxy authentication [ruby]</span>
261
+ <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 />13<br />14<br />15<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>
262
+ <span class="ident">require</span> <span class="punct">'</span><span class="string">net/ssh/proxy/http</span><span class="punct">'</span>
263
+
264
+ <span class="ident">proxy_host</span> <span class="punct">=</span> <span class="punct">'</span><span class="string">my.proxy.com</span><span class="punct">'</span>
265
+ <span class="ident">proxy_port</span> <span class="punct">=</span> <span class="number">8080</span>
266
+ <span class="ident">proxy_user</span> <span class="punct">=</span> <span class="punct">'</span><span class="string">my-name</span><span class="punct">'</span>
267
+ <span class="ident">proxy_password</span> <span class="punct">=</span> <span class="punct">'</span><span class="string">my-password</span><span class="punct">'</span>
268
+
269
+ <span class="ident">proxy</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="constant">Proxy</span><span class="punct">::</span><span class="constant">HTTP</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span> <span class="ident">proxy_host</span><span class="punct">,</span> <span class="ident">proxy_port</span><span class="punct">,</span>
270
+ <span class="symbol">:user</span> <span class="punct">=&gt;</span> <span class="ident">proxy_user</span><span class="punct">,</span>
271
+ <span class="symbol">:password</span> <span class="punct">=&gt;</span> <span class="ident">proxy_password</span> <span class="punct">)</span>
272
+
273
+ <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="symbol">:proxy</span> <span class="punct">=&gt;</span> <span class="ident">proxy</span> <span class="punct">)</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">session</span><span class="punct">|</span>
274
+ <span class="punct">...</span>
275
+ <span class="keyword">end</span></pre></div></td></tr></table></div></div>
276
+
277
+ <p>Note that currently, only basic authentication is supported; in the future, digest authentication may be added for proxies that support it.</p>
278
+ </div>
279
+
280
+
281
+
282
+ <h2>
283
+ <a name="s3"></a>
284
+ 7.3. <span class="caps">SOCKS</span>
285
+ </h2>
286
+
287
+
288
+
289
+ <div class="section">
290
+ <p>In addition to the <span class="caps">HTTP</span> proxy, Net::SSH also supports <span class="caps">SOCKS</span> proxies (both versions 4 and 5). Their usage is almost identical to the <span class="caps">HTTP</span> version (except <span class="caps">SOCKS4</span> does not use passwords, just user names):</p>
291
+
292
+ <div class='figure'>
293
+ <span class='caption'>Using SOCKS proxies [ruby]</span>
294
+ <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 />13<br />14<br />15<br />16<br />17<br />18<br />19<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>
295
+ <span class="ident">require</span> <span class="punct">'</span><span class="string">net/ssh/proxy/socks4</span><span class="punct">'</span>
296
+ <span class="ident">require</span> <span class="punct">'</span><span class="string">net/ssh/proxy/socks5</span><span class="punct">'</span>
297
+
298
+ <span class="ident">proxy_host</span> <span class="punct">=</span> <span class="punct">'</span><span class="string">my.proxy.com</span><span class="punct">'</span>
299
+ <span class="ident">proxy_port</span> <span class="punct">=</span> <span class="number">1080</span>
300
+ <span class="ident">proxy_user</span> <span class="punct">=</span> <span class="punct">'</span><span class="string">my-name</span><span class="punct">'</span>
301
+ <span class="ident">proxy_password</span> <span class="punct">=</span> <span class="punct">'</span><span class="string">my-password</span><span class="punct">'</span>
302
+
303
+ <span class="ident">socks4</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="constant">Proxy</span><span class="punct">::</span><span class="constant">SOCKS4</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span> <span class="ident">proxy_host</span><span class="punct">,</span> <span class="ident">proxy_port</span><span class="punct">,</span>
304
+ <span class="symbol">:user</span> <span class="punct">=&gt;</span> <span class="ident">proxy_user</span> <span class="punct">)</span>
305
+
306
+ <span class="ident">socks5</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="constant">Proxy</span><span class="punct">::</span><span class="constant">SOCKS5</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span> <span class="ident">proxy_host</span><span class="punct">,</span> <span class="ident">proxy_port</span><span class="punct">,</span>
307
+ <span class="symbol">:user</span> <span class="punct">=&gt;</span> <span class="ident">proxy_user</span><span class="punct">,</span>
308
+ <span class="symbol">:password</span> <span class="punct">=&gt;</span> <span class="ident">proxy_password</span><span class="punct">)</span>
309
+
310
+ <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="symbol">:proxy</span> <span class="punct">=&gt;</span> <span class="ident">socks4</span> <span class="punct">)</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">session</span><span class="punct">|</span>
311
+ <span class="punct">...</span>
312
+ <span class="keyword">end</span></pre></div></td></tr></table></div></div>
313
+ </div>
314
+
315
+
316
+
317
+ <div class="bottom"><div class="prevnext">
318
+
319
+ <a href="chapter-6.html">Previous (6. Port Forwarding)</a> |
320
+
321
+ <a href="index.html">Up</a>
322
+
323
+ </div></div>
324
+
325
+
326
+ </div>
327
+
328
+ </td></tr>
329
+ </table>
330
+ </body>
331
+ </html>