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.
- data/doc/manual-html/chapter-1.html +59 -24
- data/doc/manual-html/chapter-2.html +116 -77
- data/doc/manual-html/chapter-3.html +80 -41
- data/doc/manual-html/chapter-4.html +111 -71
- data/doc/manual-html/chapter-5.html +267 -155
- data/doc/manual-html/chapter-6.html +211 -75
- data/doc/manual-html/chapter-7.html +331 -0
- data/doc/manual-html/index.html +39 -13
- data/doc/manual-html/{manual.css → stylesheets/manual.css} +81 -8
- data/doc/manual-html/stylesheets/ruby.css +17 -0
- data/doc/manual/chapter.erb +20 -0
- data/doc/manual/manual.rb +80 -9
- data/doc/manual/manual.yml +12 -2
- data/doc/manual/page.erb +1 -1
- data/doc/manual/parts/channels_callbacks.txt +11 -11
- data/doc/manual/parts/channels_loop.txt +6 -6
- data/doc/manual/parts/channels_open.txt +9 -9
- data/doc/manual/parts/exec_channels.txt +15 -15
- data/doc/manual/parts/exec_open.txt +17 -18
- data/doc/manual/parts/exec_popen3.txt +18 -18
- data/doc/manual/parts/forward_direct.txt +16 -16
- data/doc/manual/parts/forward_intro.txt +7 -7
- data/doc/manual/parts/forward_local.txt +9 -9
- data/doc/manual/parts/forward_remote.txt +9 -9
- data/doc/manual/parts/intro_getting.txt +11 -11
- data/doc/manual/parts/proxy_http.txt +27 -27
- data/doc/manual/parts/proxy_socks.txt +17 -17
- data/doc/manual/parts/session_key.txt +13 -14
- data/doc/manual/parts/session_options.txt +14 -14
- data/doc/manual/parts/session_session.txt +9 -9
- data/doc/manual/parts/session_start.txt +27 -27
- data/doc/manual/parts/shells_channels.txt +72 -0
- data/doc/manual/parts/shells_clients.txt +51 -0
- data/doc/manual/parts/shells_intro.txt +7 -0
- data/doc/manual/parts/shells_shell.txt +50 -0
- data/doc/manual/parts/shells_sync.txt +42 -0
- data/doc/manual/{manual.css → stylesheets/manual.css} +81 -8
- data/doc/manual/stylesheets/ruby.css +17 -0
- data/examples/channel-demo.rb +1 -1
- data/examples/port-forward.rb +1 -1
- data/examples/process-demo.rb +1 -1
- data/examples/remote-net-port-forward.rb +1 -1
- data/examples/remote-port-forward.rb +1 -1
- data/examples/shell-demo.rb +46 -0
- data/examples/ssh-client.rb +67 -0
- data/examples/sync-shell-demo.rb +69 -0
- data/examples/tail-demo.rb +1 -1
- data/lib/net/ssh.rb +1 -1
- data/lib/net/ssh/connection/channel.rb +61 -7
- data/lib/net/ssh/connection/constants.rb +1 -1
- data/lib/net/ssh/connection/driver.rb +61 -8
- data/lib/net/ssh/connection/services.rb +1 -1
- data/lib/net/ssh/connection/term.rb +1 -1
- data/lib/net/ssh/errors.rb +1 -1
- data/lib/net/ssh/proxy/errors.rb +1 -1
- data/lib/net/ssh/proxy/http.rb +1 -1
- data/lib/net/ssh/proxy/socks4.rb +1 -1
- data/lib/net/ssh/proxy/socks5.rb +1 -1
- data/lib/net/ssh/service/forward/driver.rb +1 -1
- data/lib/net/ssh/service/forward/local-network-handler.rb +1 -1
- data/lib/net/ssh/service/forward/remote-network-handler.rb +1 -1
- data/lib/net/ssh/service/forward/services.rb +1 -1
- data/lib/net/ssh/service/process/driver.rb +1 -1
- data/lib/net/ssh/service/process/open.rb +1 -1
- data/lib/net/ssh/service/process/popen3.rb +20 -2
- data/lib/net/ssh/service/process/services.rb +1 -1
- data/lib/net/ssh/service/services.rb +3 -1
- data/lib/net/ssh/service/shell/driver.rb +86 -0
- data/lib/net/ssh/service/shell/services.rb +54 -0
- data/lib/net/ssh/service/shell/shell.rb +213 -0
- data/lib/net/ssh/service/shell/sync.rb +114 -0
- data/lib/net/ssh/session.rb +9 -1
- data/lib/net/ssh/transport/algorithm-negotiator.rb +1 -1
- data/lib/net/ssh/transport/compress/compressor.rb +1 -1
- data/lib/net/ssh/transport/compress/decompressor.rb +1 -1
- data/lib/net/ssh/transport/compress/none-compressor.rb +1 -1
- data/lib/net/ssh/transport/compress/none-decompressor.rb +1 -1
- data/lib/net/ssh/transport/compress/services.rb +1 -1
- data/lib/net/ssh/transport/compress/zlib-compressor.rb +1 -1
- data/lib/net/ssh/transport/compress/zlib-decompressor.rb +1 -1
- data/lib/net/ssh/transport/constants.rb +1 -1
- data/lib/net/ssh/transport/errors.rb +1 -1
- data/lib/net/ssh/transport/identity-cipher.rb +1 -1
- data/lib/net/ssh/transport/kex/dh-gex.rb +1 -1
- data/lib/net/ssh/transport/kex/dh.rb +1 -1
- data/lib/net/ssh/transport/kex/services.rb +1 -1
- data/lib/net/ssh/transport/ossl/buffer-factory.rb +1 -1
- data/lib/net/ssh/transport/ossl/buffer.rb +1 -1
- data/lib/net/ssh/transport/ossl/cipher-factory.rb +1 -1
- data/lib/net/ssh/transport/ossl/digest-factory.rb +1 -1
- data/lib/net/ssh/transport/ossl/hmac-factory.rb +1 -1
- data/lib/net/ssh/transport/ossl/hmac/hmac.rb +1 -1
- data/lib/net/ssh/transport/ossl/hmac/md5-96.rb +1 -1
- data/lib/net/ssh/transport/ossl/hmac/md5.rb +1 -1
- data/lib/net/ssh/transport/ossl/hmac/none.rb +1 -1
- data/lib/net/ssh/transport/ossl/hmac/services.rb +1 -1
- data/lib/net/ssh/transport/ossl/hmac/sha1-96.rb +1 -1
- data/lib/net/ssh/transport/ossl/hmac/sha1.rb +1 -1
- data/lib/net/ssh/transport/ossl/key-factory.rb +5 -2
- data/lib/net/ssh/transport/ossl/services.rb +1 -1
- data/lib/net/ssh/transport/packet-stream.rb +1 -1
- data/lib/net/ssh/transport/services.rb +1 -1
- data/lib/net/ssh/transport/session.rb +10 -1
- data/lib/net/ssh/transport/version-negotiator.rb +1 -1
- data/lib/net/ssh/userauth/agent.rb +1 -1
- data/lib/net/ssh/userauth/constants.rb +1 -1
- data/lib/net/ssh/userauth/driver.rb +1 -1
- data/lib/net/ssh/userauth/methods/hostbased.rb +1 -1
- data/lib/net/ssh/userauth/methods/keyboard-interactive.rb +104 -0
- data/lib/net/ssh/userauth/methods/password.rb +1 -1
- data/lib/net/ssh/userauth/methods/publickey.rb +1 -1
- data/lib/net/ssh/userauth/methods/services.rb +28 -6
- data/lib/net/ssh/userauth/services.rb +8 -5
- data/lib/net/ssh/userauth/userkeys.rb +1 -1
- data/lib/net/ssh/util/buffer.rb +1 -1
- data/lib/net/ssh/util/openssl.rb +1 -1
- data/lib/net/ssh/util/prompter.rb +1 -1
- data/lib/net/ssh/version.rb +2 -2
- data/test/ALL-TESTS.rb +1 -1
- data/test/connection/tc_channel.rb +1 -1
- data/test/connection/tc_driver.rb +1 -1
- data/test/connection/tc_integration.rb +1 -1
- data/test/proxy/tc_http.rb +1 -1
- data/test/proxy/tc_socks4.rb +1 -1
- data/test/proxy/tc_socks5.rb +1 -1
- data/test/service/forward/tc_driver.rb +1 -1
- data/test/service/forward/tc_local_network_handler.rb +1 -1
- data/test/service/forward/tc_remote_network_handler.rb +1 -1
- data/test/service/process/tc_driver.rb +1 -1
- data/test/service/process/tc_integration.rb +1 -1
- data/test/service/process/tc_open.rb +1 -1
- data/test/service/process/tc_popen3.rb +13 -13
- data/test/tc_integration.rb +1 -1
- data/test/transport/compress/tc_none_compress.rb +1 -1
- data/test/transport/compress/tc_none_decompress.rb +1 -1
- data/test/transport/compress/tc_zlib_compress.rb +1 -1
- data/test/transport/compress/tc_zlib_decompress.rb +1 -1
- data/test/transport/kex/tc_dh.rb +2 -1
- data/test/transport/kex/tc_dh_gex.rb +1 -1
- data/test/transport/ossl/hmac/tc_hmac.rb +1 -1
- data/test/transport/ossl/hmac/tc_md5.rb +1 -1
- data/test/transport/ossl/hmac/tc_md5_96.rb +1 -1
- data/test/transport/ossl/hmac/tc_none.rb +1 -1
- data/test/transport/ossl/hmac/tc_sha1.rb +1 -1
- data/test/transport/ossl/hmac/tc_sha1_96.rb +1 -1
- data/test/transport/ossl/tc_buffer.rb +1 -1
- data/test/transport/ossl/tc_buffer_factory.rb +1 -1
- data/test/transport/ossl/tc_cipher_factory.rb +1 -1
- data/test/transport/ossl/tc_digest_factory.rb +1 -1
- data/test/transport/ossl/tc_hmac_factory.rb +1 -1
- data/test/transport/ossl/tc_key_factory.rb +1 -1
- data/test/transport/tc_algorithm_negotiator.rb +1 -1
- data/test/transport/tc_identity_cipher.rb +1 -1
- data/test/transport/tc_integration.rb +1 -1
- data/test/transport/tc_packet_stream.rb +1 -1
- data/test/transport/tc_session.rb +1 -1
- data/test/transport/tc_version_negotiator.rb +1 -1
- data/test/userauth/methods/tc_hostbased.rb +1 -1
- data/test/userauth/methods/tc_password.rb +1 -1
- data/test/userauth/methods/tc_publickey.rb +1 -1
- data/test/userauth/tc_agent.rb +1 -1
- data/test/userauth/tc_driver.rb +1 -1
- data/test/userauth/tc_integration.rb +15 -1
- data/test/userauth/tc_userkeys.rb +1 -1
- data/test/util/tc_buffer.rb +5 -5
- metadata +26 -6
@@ -4,11 +4,11 @@ In order to allow the events to be processed in a continuous manner, you need to
|
|
4
4
|
|
5
5
|
The @loop@ method is easy to invoke:
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
[!figure lang=ruby,caption=Session#loop,number=true
|
8
|
+
Net::SSH.start( 'host' ) do |session|
|
9
|
+
...
|
10
|
+
session.loop
|
11
|
+
end
|
12
|
+
!]
|
13
13
|
|
14
14
|
Incidentally, the @loop@ method accepts an optional block, which if specified should return a "false" value when the loop should terminate. In the absense of a block, the loop will continue until there are no more open channels. Sometimes, however, you only want the loop to continue until some action occurs, at which time you then do some processing and then start the loop again.
|
@@ -6,15 +6,15 @@ This behavior is typical of most of the methods in the Net::SSH API; they simply
|
|
6
6
|
|
7
7
|
Here is an example of opening a channel:
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
session.loop
|
9
|
+
[!figure lang=ruby,caption=Opening a channel,number=true
|
10
|
+
Net::SSH.start( 'host' ) do |session|
|
11
|
+
session.open_channel do |channel|
|
12
|
+
puts "channel successfully opened... closing..."
|
13
|
+
channel.close
|
17
14
|
end
|
18
|
-
|
15
|
+
|
16
|
+
session.loop
|
17
|
+
end
|
18
|
+
!]
|
19
19
|
|
20
20
|
Note the use of the @close@ method for the channel. Just like most methods in the Net::SSH API, it does not immediately close the channel, but instead sends a close request to the server and returns. When the server responds that the channel has been closed, the framework will then call any final callbacks for the channel and then remove it.
|
@@ -2,24 +2,24 @@ To run multiple processes in parallel, you can access the channel API directly,
|
|
2
2
|
|
3
3
|
Suppose, for example, that you wanted to run multiple "tail" commands on various logs on the remote machine, combining them all into the output on the client. Something like the following would suffice:
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
channel.exec "tail -f #{file}"
|
5
|
+
[!figure lang=ruby,number=true,caption=Running "tail" on multiple remote files
|
6
|
+
def do_tail( session, file )
|
7
|
+
session.open_channel do |channel|
|
8
|
+
channel.on_data do |ch, data|
|
9
|
+
puts "[#{file}] -> #{data}"
|
12
10
|
end
|
11
|
+
channel.exec "tail -f #{file}"
|
13
12
|
end
|
13
|
+
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
Net::SSH.start( 'host' ) do |session|
|
16
|
+
do_tail session, "/var/log/messages"
|
17
|
+
do_tail session, "/var/log/XFree86.0.log"
|
18
|
+
do_tail session, "/var/log/tomcat/catalina.log"
|
19
|
+
do_tail session, "/var/log/mysql/mysql.err"
|
20
|
+
session.loop
|
21
|
+
end
|
22
|
+
!]
|
23
23
|
|
24
24
|
As you can see, four different logs are tailed on four separate channels. Each channel registers an @on_data@ callback (which simply displays the data it recieves, together with the name of the log file it came from). The @exec@ method of the channel is then invoked, which simply sends the request to execute the process to the server, and then returns.
|
25
25
|
|
@@ -4,33 +4,32 @@ Just open an SSH session. The @#process@ service of the session manages access t
|
|
4
4
|
|
5
5
|
Consider the "bc" command. It is a command-line calculator that accepts expressions on @stdin@ and writes the results to @stdout@. When it encounters the word @quit@ on the input, it exits. Sounds like a great way to demonstrate the @process@ service...
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
[!figure lang=ruby,number=true,caption=Using #process.open
|
8
|
+
Net::SSH.start( 'host' ) do |session|
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
session.process.open( "bc" ) do |bc|
|
11
|
+
dialog = [ "5+5", "7*12", "sqrt(2.000000)", "quit" ]
|
12
12
|
|
13
|
-
|
13
|
+
bc.on_success do |p|
|
14
|
+
puts "requesting result of #{dialog.first}"
|
15
|
+
p.puts dialog.shift
|
16
|
+
end
|
17
|
+
|
18
|
+
bc.on_stdout do |p,data|
|
19
|
+
puts "--> #{data}"
|
20
|
+
unless dialog.empty?
|
14
21
|
puts "requesting result of #{dialog.first}"
|
15
22
|
p.puts dialog.shift
|
16
23
|
end
|
17
|
-
|
18
|
-
bc.on_stdout do |p,data|
|
19
|
-
puts "--> #{data}"
|
20
|
-
unless dialog.empty?
|
21
|
-
puts "requesting result of #{dialog.first}"
|
22
|
-
p.puts dialog.shift
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
bc.on_exit do |p, status|
|
27
|
-
puts "process finished with exit status: #{status}"
|
28
|
-
end
|
29
24
|
end
|
30
25
|
|
26
|
+
bc.on_exit do |p, status|
|
27
|
+
puts "process finished with exit status: #{status}"
|
28
|
+
end
|
31
29
|
end
|
32
|
-
</pre>
|
33
30
|
|
31
|
+
end
|
32
|
+
!]
|
34
33
|
|
35
34
|
Notice the progression. First, the session itself is started. Then, while the session is active, the process is invoked (via @#process.open@). After we have a handle to the process (which is yielded to the block, in this case), we set up the callbacks on the process. These are reminiscent of, but different from, the callbacks that we set up on the channel itself in the previous section.
|
36
35
|
|
@@ -4,32 +4,32 @@ If you are familiar with the "popen3" Ruby module, this will seem familiar. It's
|
|
4
4
|
|
5
5
|
Here's the previous "bc" example, rewritten to use @#popen3@:
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
[!figure lang=ruby,number=true,caption=Using #process.popen3
|
8
|
+
Net::SSH.start( 'host' ) do |session|
|
9
9
|
|
10
|
-
|
10
|
+
input, output, error = session.process.popen3( "bc" )
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
[ "5+5", "7*12", "sqrt(2.000000)" ].each do |formula|
|
13
|
+
input.puts formula
|
14
|
+
puts "#{formula}=#{output.read}"
|
15
|
+
end
|
16
16
|
|
17
|
-
|
17
|
+
input.puts "quit"
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
end
|
20
|
+
!]
|
21
21
|
|
22
22
|
Much more concise, isn't it? One caveat, though: there is no way to kill the process (unless the process can terminate itself, such as through the use of issuing bc's "quit" command as used above) without closing the session. To remedy this, there is also a block version of popen3 that provides an explicit scope for the three data streams:
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
24
|
+
[!figure lang=ruby,number=true,caption=Transactional form of #process.popen3
|
25
|
+
Net::SSH.start( 'host' ) do |session|
|
26
|
+
session.process.popen3( "bc" ) do |input, output, error|
|
27
|
+
[ "5+5", "7*12", "sqrt(2.000000)" ].each do |formula|
|
28
|
+
input.puts formula
|
29
|
+
puts "#{formula}=#{output.read}"
|
31
30
|
end
|
32
31
|
end
|
33
|
-
|
32
|
+
end
|
33
|
+
!]
|
34
34
|
|
35
35
|
The three streams will be closed and process explicitly terminated when the block ends.
|
@@ -14,24 +14,24 @@ table(list).
|
|
14
14
|
|
15
15
|
For example, the following example pretends to be a client that has connected to the local host on a forwarded port:
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
def process( channel )
|
25
|
-
channel.send_data "initial request"
|
26
|
-
end
|
17
|
+
[!figure lang=ruby,number=true,caption=Using a handler object to mimic a forwarded port
|
18
|
+
class Handler
|
19
|
+
def on_receive( channel, data )
|
20
|
+
puts "got data: #{data.inspect}"
|
21
|
+
channel.send_data "subsequent request"
|
27
22
|
end
|
28
23
|
|
29
|
-
|
30
|
-
|
31
|
-
4321, Handler.new )
|
32
|
-
|
33
|
-
session.loop
|
24
|
+
def process( channel )
|
25
|
+
channel.send_data "initial request"
|
34
26
|
end
|
35
|
-
|
27
|
+
end
|
28
|
+
|
29
|
+
Net::SSH.start( 'host' ) do |session|
|
30
|
+
session.forward.direct_channel( 1234, 'somewhere.else.net',
|
31
|
+
4321, Handler.new )
|
32
|
+
|
33
|
+
session.loop
|
34
|
+
end
|
35
|
+
!]
|
36
36
|
|
37
37
|
The local port number for @#direct_channel@ has no real purpose, other than to report to the SSH server that the "virtual" connection occurred on that port.
|
@@ -5,13 +5,13 @@ Port forwarding is a feature of the SSH protocol that allows you to specify a po
|
|
5
5
|
|
6
6
|
All port forwarding in the Net::SSH library is managed by the @#forward@ service. Just invoke methods on that service to set up any of various port forwarding configurations.
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
8
|
+
[!figure lang=ruby,number=true,caption=Accessing the #forward service
|
9
|
+
Net::SSH.start( 'host' ) do |session|
|
10
|
+
forward = session.forward
|
11
|
+
...
|
12
|
+
session.loop
|
13
|
+
end
|
14
|
+
!]
|
15
15
|
|
16
16
|
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't SSH lovely?)
|
17
17
|
|
@@ -1,18 +1,18 @@
|
|
1
1
|
Forwarding a local connection to a remote destination is simply a matter of invoking the @#local@ method of the @#forward@ 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:
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
[!figure lang=ruby,number=true,caption=Forwarding a local port
|
4
|
+
Net::SSH.start( 'host' ) do |session|
|
5
|
+
session.forward.local( 1234, 'www.google.com', 80 )
|
6
|
+
session.loop
|
7
|
+
end
|
8
|
+
!]
|
9
9
|
|
10
10
|
In the above example, then, any connection received on port 1234 will be forwarded to port 80 on "www.google.com". This means that if you were to point a browser at "http://localhost:1234", it would pull up "Google":http://www.google.com.
|
11
11
|
|
12
12
|
By default, only connections _from the local host_ 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 @#local@, with the local port number immediately following.
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
[!figure lang=ruby,caption=Specifying the bind address when forwarding a local port
|
15
|
+
session.forward.local( '0.0.0.0', 1234, 'www.google.com', 80 )
|
16
|
+
!]
|
17
17
|
|
18
18
|
In this configuration, anyone from anywhere can connect to your machine on port 1234 and be forwarded to Google.
|
@@ -1,14 +1,14 @@
|
|
1
1
|
Forwarding remote connections to the local host is also straightforward; simply call the @#remote_to@ method of the @#forward@ 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 "127.0.0.1".
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
[!figure lang=ruby,number=true,caption=Forwarding a remote port
|
4
|
+
Net::SSH.start( 'host' ) do |session|
|
5
|
+
session.forward.remote_to( 80, 'www.google.com', 1234 )
|
6
|
+
session.loop
|
7
|
+
end
|
8
|
+
!]
|
9
9
|
|
10
10
|
The above example causes any connection on port 1234 of the remote machine (_from_ 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:
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
[!figure lang=ruby,caption=Specifying the bind address when forwarding a remote port
|
13
|
+
session.forward.remote_to( 80, 'www.google.com', 1234, '0.0.0.0' )
|
14
|
+
!]
|
@@ -10,9 +10,9 @@ h3. Using "RubyGems":http://rubygems.rubyforge.org
|
|
10
10
|
|
11
11
|
If you have "RubyGems":http://rubygems.rubyforge.org installed, installing Net::SSH is simple:
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
[!figure lang=shell,caption=Using Rubygems to install Net::SSH
|
14
|
+
gem install net-ssh
|
15
|
+
!]
|
16
16
|
|
17
17
|
You still need to make sure you have a working version of Ruby's OpenSSL module, but other than that, you should be good to go!
|
18
18
|
|
@@ -20,9 +20,9 @@ h3. Using "rpa-base":http://rpa-base.rubyforge.org
|
|
20
20
|
|
21
21
|
If you have "rpa-base":http://rpa-base.rubyforge.org installed:
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
[!figure lang=shell,caption=Using RPA to install Net::SSH
|
24
|
+
rpa install net-ssh
|
25
|
+
!]
|
26
26
|
|
27
27
|
As with the gem install, you still need to make sure you have a working version of Ruby's OpenSSL module, but other than that, you should be good to go!
|
28
28
|
|
@@ -32,8 +32,8 @@ If you don't have "RubyGems":http://rubygems.rubyforge.org or "rpa-base":http://
|
|
32
32
|
|
33
33
|
Then, unpack the archive and run the @setup.rb@ script:
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
[!figure lang=shell,caption=Using setup.rb to install Net::SSH
|
36
|
+
ruby setup.rb config
|
37
|
+
ruby setup.rb setup
|
38
|
+
ruby setup.rb install
|
39
|
+
!]
|
@@ -1,17 +1,17 @@
|
|
1
1
|
If you have an HTTP proxy running, you may be able to use it to your advantage. The following snippet demonstrates how to tunnel an SSH connection through an HTTP proxy:
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
[!figure lang=ruby,number=true,caption=Tunnelling an SSH connection over HTTP
|
4
|
+
require 'net/ssh'
|
5
|
+
require 'net/ssh/proxy/http'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
proxy_host = 'my.proxy.com'
|
8
|
+
proxy_port = 8080
|
9
|
+
proxy = Net::SSH::Proxy::HTTP.new( proxy_host, proxy_port )
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
Net::SSH.start( 'host', :proxy => proxy ) do |session|
|
12
|
+
...
|
13
|
+
end
|
14
|
+
!]
|
15
15
|
|
16
16
|
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 HTTP and SOCKS are available.)
|
17
17
|
|
@@ -21,9 +21,9 @@ Note: If your proxy does not allow connects to be made to other hosts on port 22
|
|
21
21
|
|
22
22
|
For instance, if your proxy disallows connections to any port except (say) 443, you could run the following command on the remote host:
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
[!figure lang=shell,caption=Forwarding a port using the ssh command
|
25
|
+
ssh -gL 443:localhost:22 localhost
|
26
|
+
!]
|
27
27
|
|
28
28
|
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't access that machine in the first place (ie, because you're behind a firewall), then it does you no good.
|
29
29
|
|
@@ -31,22 +31,22 @@ h3. Proxy Authentication
|
|
31
31
|
|
32
32
|
Some proxies require authentication. Net::SSH supports these proxies as well. If you specify the user name either as a @:user@ option to the HTTP proxy constructor, or in the @HTTP_PROXY_USER@ or @CONNECT_USER@ environment variables, that name will be used to authenticate with the proxy. Likewise, the password may be given either via the @:password@ constructor option, or via the @HTTP_PROXY_PASSWORD@ or @CONNECT_PASSWORD@ environment variables.
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
[!figure lang=ruby,number=true,caption=Using HTTP proxy authentication
|
35
|
+
require 'net/ssh'
|
36
|
+
require 'net/ssh/proxy/http'
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
proxy_host = 'my.proxy.com'
|
39
|
+
proxy_port = 8080
|
40
|
+
proxy_user = 'my-name'
|
41
|
+
proxy_password = 'my-password'
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
proxy = Net::SSH::Proxy::HTTP.new( proxy_host, proxy_port,
|
44
|
+
:user => proxy_user,
|
45
|
+
:password => proxy_password )
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
Net::SSH.start( 'host', :proxy => proxy ) do |session|
|
48
|
+
...
|
49
|
+
end
|
50
|
+
!]
|
51
51
|
|
52
52
|
Note that currently, only basic authentication is supported; in the future, digest authentication may be added for proxies that support it.
|
@@ -1,23 +1,23 @@
|
|
1
1
|
In addition to the HTTP proxy, Net::SSH also supports SOCKS proxies (both versions 4 and 5). Their usage is almost identical to the HTTP version (except SOCKS4 does not use passwords, just user names):
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
[!figure lang=ruby,number=true,caption=Using SOCKS proxies
|
4
|
+
require 'net/ssh'
|
5
|
+
require 'net/ssh/proxy/socks4'
|
6
|
+
require 'net/ssh/proxy/socks5'
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
proxy_host = 'my.proxy.com'
|
9
|
+
proxy_port = 1080
|
10
|
+
proxy_user = 'my-name'
|
11
|
+
proxy_password = 'my-password'
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
socks4 = Net::SSH::Proxy::SOCKS4.new( proxy_host, proxy_port,
|
14
|
+
:user => proxy_user )
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
socks5 = Net::SSH::Proxy::SOCKS5.new( proxy_host, proxy_port,
|
17
|
+
:user => proxy_user,
|
18
|
+
:password => proxy_password)
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
Net::SSH.start( 'host', :proxy => socks4 ) do |session|
|
21
|
+
...
|
22
|
+
end
|
23
|
+
!]
|