File: README.rdoc

package info (click to toggle)
ruby-net-ssh 1%3A3.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,520 kB
  • ctags: 1,913
  • sloc: ruby: 13,740; makefile: 3
file content (182 lines) | stat: -rw-r--r-- 6,587 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
= Net::SSH 3.x

<em><b>Please note: this project is in maintenance mode. It is not under active development but pull requests are very much welcome. Just be sure to include tests! -- delano</b></em>


* Docs: http://net-ssh.github.com/net-ssh
* Issues: https://github.com/net-ssh/net-ssh/issues
* Codes: https://github.com/net-ssh/net-ssh
* Email: net-ssh@solutious.com


<em>As of v2.6.4, all gem releases are signed. See INSTALL.</em>


== DESCRIPTION:

Net::SSH is a pure-Ruby implementation of the SSH2 client protocol. It allows you to write programs that invoke and interact with processes on remote servers, via SSH2.

== FEATURES:

* Execute processes on remote servers and capture their output
* Run multiple processes in parallel over a single SSH connection
* Support for SSH subsystems
* Forward local and remote ports via an SSH connection

== SYNOPSIS:

In a nutshell:

  require 'net/ssh'

  Net::SSH.start('host', 'user', :password => "password") do |ssh|
    # capture all stderr and stdout output from a remote process
    output = ssh.exec!("hostname")
    puts output

    # capture only stdout matching a particular pattern
    stdout = ""
    ssh.exec!("ls -l /home/jamis") do |channel, stream, data|
      stdout << data if stream == :stdout
    end
    puts stdout

    # run multiple processes in parallel to completion
    ssh.exec "sed ..."
    ssh.exec "awk ..."
    ssh.exec "rm -rf ..."
    ssh.loop

    # open a new channel and configure a minimal set of callbacks, then run
    # the event loop until the channel finishes (closes)
    channel = ssh.open_channel do |ch|
      ch.exec "/usr/local/bin/ruby /path/to/file.rb" do |ch, success|
        raise "could not execute command" unless success

        # "on_data" is called when the process writes something to stdout
        ch.on_data do |c, data|
          $stdout.print data
        end

        # "on_extended_data" is called when the process writes something to stderr
        ch.on_extended_data do |c, type, data|
          $stderr.print data
        end

        ch.on_close { puts "done!" }
      end
    end

    channel.wait

    # forward connections on local port 1234 to port 80 of www.capify.org
    ssh.forward.local(1234, "www.capify.org", 80)
    ssh.loop { true }
  end

See Net::SSH for more documentation, and links to further information.

== REQUIREMENTS:

The only requirement you might be missing is the OpenSSL bindings for Ruby. These are built by default on most platforms, but you can verify that they're built and installed on your system by running the following command line:

  ruby -ropenssl -e 'puts OpenSSL::OPENSSL_VERSION'

If that spits out something like "OpenSSL 0.9.8g 19 Oct 2007", then you're set. If you get an error, then you'll need to see about rebuilding ruby with OpenSSL support, or (if your platform supports it) installing the OpenSSL bindings separately.

Additionally: if you are going to be having Net::SSH prompt you for things like passwords or certificate passphrases, you'll want to have either the Highline (recommended) or Termios (unix systems only) gem installed, so that the passwords don't echo in clear text.

Lastly, if you want to run the tests or use any of the Rake tasks, you'll need:

* Echoe (for the Rakefile)
* Mocha (for the tests)


== INSTALL:

* gem install net-ssh (might need sudo privileges)

NOTE: If you are running on jruby you need to install jruby-pageant manually (gemspec doesn't allow for platform specific dependencies).

However, in order to be sure the code you're installing hasn't been tampered with, it's recommended that you verify the signature[http://docs.rubygems.org/read/chapter/21]. To do this, you need to add my public key as a trusted certificate (you only need to do this once):

    # Add the public key as a trusted certificate
    # (You only need to do this once)
    $ curl -O https://raw.githubusercontent.com/net-ssh/net-ssh/master/net-ssh-public_cert.pem
    $ gem cert --add net-ssh-public_cert.pem

Then, when install the gem, do so with high security:

    $ gem install net-ssh -P HighSecurity

If you don't add the public key, you'll see an error like "Couldn't verify data signature". If you're still having trouble let me know and I'll give you a hand.

== RUBY 1.x SUPPORT

* Ruby 1.8.x is supported up until the net-ssh 2.5.1 release.
* Ruby 1.9.x is supported up until the net-ssh 2.9.x release.
* Current net-ssh releases require Ruby 2.0 or later.

== RUNNING TESTS

Run the test suite from the net-ssh directory with the following command:

     bash -c 'unset HOME && ruby -Ilib -Itest -rrubygems test/test_all.rb'

Run a single test file like this:

     ruby -Ilib -Itest -rrubygems test/transport/test_server_version.rb

To run integration tests see test/integration/README.txt

=== BUILDING GEM

Since building the gem requires the private key if you want to build a .gem locally please use the NET_SSH_NOKEY=1 envirnoment variable:

     rake build NET_SSH_NOKEY=1

=== PORT FORWARDING TESTS

     ruby -Ilib -Itest -rrubygems test/manual/test_forward.rb

test_forward.rb must be run separately from the test suite because
it requires authorizing your public SSH keys on you localhost.

If you already have keys you can do this:

     cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

If you don't have keys see:

     http://kimmo.suominen.com/docs/ssh/#ssh-keygen

You should now be able to login to your localhost with out
bring prompted for a password:

     ssh localhost


== LICENSE:

(The MIT License)

Copyright (c) 2008 Jamis Buck

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.