Giter Site home page Giter Site logo

nickhammond / net-ssh Goto Github PK

View Code? Open in Web Editor NEW

This project forked from net-ssh/net-ssh

0.0 1.0 0.0 7.34 MB

Pure Ruby implementation of an SSH (protocol 2) client

Home Page: http://net-ssh.github.com/net-ssh

License: MIT License

Ruby 100.00%

net-ssh's Introduction

Gem Version Join the chat at https://gitter.im/net-ssh/net-ssh Build Status Coverage status Backers on Open Collective Sponsors on Open Collective

Net::SSH 5.x

As of v2.6.4, all gem releases are signed. See INSTALL.

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 with a version greather than 1.0.1. 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 1.0.1 14 Mar 2012, 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.

INSTALL:

gem install net-ssh # might need sudo privileges

NOTE: If you are running on jruby on windows 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. 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.

For ed25519 public key auth support your bundle file should contain ed25519, bcrypt_pbkdf dependencies.

gem install ed25519
gem install bcrypt_pbkdf

RUBY SUPPORT

RUNNING TESTS

If you want to run the tests or use any of the Rake tasks, you'll need Mocha and other dependencies listed in Gemfile

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

bundle exec rake test

Run a single test file like this:

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

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

BUILDING GEM

rake build

GEM SIGNING (for maintainers)

If you have the net-ssh private signing key, you will be able to create signed release builds. Make sure the private key path matches the signing_key path set in net-ssh.gemspec and tell rake to sign the gem by setting the NET_SSH_BUILDGEM_SIGNED flag:

NET_SSH_BUILDGEM_SIGNED=true rake build

For time to time, the public certificate associated to the private key needs to be renewed. You can do this with the following command:

gem cert --build [email protected] --private-key path/2/net-ssh-private_key.pem
mv gem-public_cert.pem net-ssh-public_cert.pem
gem cert --add net-ssh-public_cert.pem

CREDITS

Contributors

This project exists thanks to all the people who contribute.

contributors

Backers

Thank you to all our backers! ๐Ÿ™ Become a backer

backers

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. Become a sponsor

Sponsor

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.

net-ssh's People

Contributors

ab avatar amatsuda avatar arturaz avatar bartle-stripe avatar byroot avatar carlhoerberg avatar chortleoo avatar chr4 avatar chrahunt avatar clupprich avatar dazuma avatar delano avatar dubspeed avatar fwininger avatar gabklein avatar graffic avatar hanazuki avatar hsitter avatar jamis avatar jaredbeck avatar jonasabromaitis avatar jwoertink avatar kachick avatar knu avatar masa0x80 avatar mfazekas avatar musybite avatar nappa avatar nessche avatar sah avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.