GithubHelp home page GithubHelp logo

net-ssh / net-ssh Goto Github PK

View Code? Open in Web Editor NEW
968.0 968.0 441.0 7.43 MB

Pure Ruby implementation of an SSH (protocol 2) client

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

License: MIT License

Ruby 99.90% Dockerfile 0.10%

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 7.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

Supported Algorithms

Net::SSH 6.0 disables by default the usage of weak algorithms. We strongly recommend that you install a servers's version that supports the latest algorithms.

It is possible to return to the previous behavior by adding the option : append_all_supported_algorithms: true

Unsecure algoritms will definitely be removed in Net::SSH 8.*.

Host Keys

Name Support Details
ssh-rsa OK
ssh-ed25519 OK Require the gem ed25519
ecdsa-sha2-nistp521 OK using weak elliptic curves
ecdsa-sha2-nistp384 OK using weak elliptic curves
ecdsa-sha2-nistp256 OK using weak elliptic curves
ssh-dss Deprecated in 6.0 unsecure, will be removed in 8.0

Key Exchange

Name Support Details
curve25519-sha256 OK Require the gem x25519
ecdh-sha2-nistp521 OK using weak elliptic curves
ecdh-sha2-nistp384 OK using weak elliptic curves
ecdh-sha2-nistp256 OK using weak elliptic curves
diffie-hellman-group1-sha1 Deprecated in 6.0 unsecure, will be removed in 8.0
diffie-hellman-group14-sha1 OK
diffie-hellman-group-exchange-sha1 Deprecated in 6.0 unsecure, will be removed in 8.0
diffie-hellman-group-exchange-sha256 OK

Encryption algorithms (ciphers)

Name Support Details
aes256-ctr / aes192-ctr / aes128-ctr OK
[email protected] OK. Requires the gem rbnacl
aes256-cbc / aes192-cbc / aes128-cbc Deprecated in 6.0 unsecure, will be removed in 8.0
[email protected] Deprecated in 6.0 unsecure, will be removed in 8.0
blowfish-ctr blowfish-cbc Deprecated in 6.0 unsecure, will be removed in 8.0
cast128-ctr cast128-cbc Deprecated in 6.0 unsecure, will be removed in 8.0
3des-ctr 3des-cbc Deprecated in 6.0 unsecure, will be removed in 8.0
idea-cbc Deprecated in 6.0 unsecure, will be removed in 8.0
none Deprecated in 6.0 unsecure, will be removed in 8.0

Message Authentication Code algorithms

Name Support Details
hmac-sha2-512-etm OK
hmac-sha2-256-etm OK
hmac-sha2-512 OK
hmac-sha2-256 OK
hmac-sha2-512-96 Deprecated in 6.0 removed from the specification, will be removed in 8.0
hmac-sha2-256-96 Deprecated in 6.0 removed from the specification, will be removed in 8.0
hmac-sha1 OK for backward compatibility
hmac-sha1-96 Deprecated in 6.0 unsecure, will be removed in 8.0
hmac-ripemd160 Deprecated in 6.0 unsecure, will be removed in 8.0
hmac-md5 Deprecated in 6.0 unsecure, will be removed in 8.0
hmac-md5-96 Deprecated in 6.0 unsecure, will be removed in 8.0
none Deprecated in 6.0 unsecure, will be removed in 8.0

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 && /foo/.match(data)
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 at gem installation time).

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

For curve25519-sha256 kex exchange support your bundle file should contain x25519 dependency.

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

NOTE : you can run test on all ruby versions with docker :

docker-compose up --build

Run a single test file like this:

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

To run integration tests see here

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

or rake cert:update_public_when_expired

Security contact information

See SECURITY.md

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 anderscarling avatar arturaz avatar bschmeck avatar byroot avatar carlhoerberg avatar chortleoo avatar chr4 avatar chrahunt avatar clupprich avatar delano avatar dubspeed avatar fwininger avatar gabklein avatar hsitter avatar jamis avatar kachick avatar knu avatar lapizistik avatar masa0x80 avatar mattbrictson avatar mfazekas avatar musybite avatar nappa avatar nessche avatar sah avatar schopin-pro avatar sskousen avatar zeos90 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

net-ssh's Issues

Option to customize prompting

The set of prompting options is hard-coded in Net::SSH::Prompt. I would like to use a custom prompt module (that does caching), which is not possible currently without monkey patching Net::SSH.

On a related front (which perhaps should be a separate ticket) it would probably be useful to also just give users an option to simply disable prompting, similar to BatchMode=yes in the command line ssh. In Net::SSH::Authentication::KeyManager#each_identity the call to load_identities has the ask_passphrase parameter hard-coded to true.

net-scp patch version increased net-ssh dependency minor version

net-scp 1.0.5/1.0.6 was released today, and as far as I can see the only thing it did was increase the net-ssh dependency to ">= 2.6.5" whereas 1.0.5 was ">= 1.99.1."

I maintain Vagrant which previously locked to net-ssh ~> 2.2.2 and net-scp ~> 1.0.4 for a stable series (1.0.x). I simply cannot justify risking Vagrant stability by upgrading from 2.2 to 2.6 of net-ssh. I took a look at the CHANGES.txt and the changes are not insignificant.

In my opinion, a patch version shouldn't do anything that even remotely risks breaking existing applications, and I don't feel confident in this when the minor versions are increasing.

Please restrict net-scp back to ">= 1.99.1" and release a net-scp 1.1.0 that changes minor version dependencies.

net-ssh 2.4.0 fails tests

With ruby 1.8.7 (2012-03-02 patchlevel 359) [x86_64-linux] I'm getting the following test failures.

Failure:
test_load_with_no_host(TestConfig)
./test_config.rb:44:in `test_load_with_no_host'
/usr/lib64/ruby/gems/1.8/gems/mocha-0.10.5/lib/mocha/integration/test_unit/gem_version_230_to_240.rb:25:in `run'
     22:             begin
     23:               begin
     24:                 run_setup
  => 25:                 run_test
     26:                 run_cleanup
     27:                 mocha_verify(assertion_counter)
     28:                 add_pass
<["~/.ssh/id_dsa", "~/.ssh/id_rsa"]> expected but was
<nil>

diff:
? ["~/.ssh/id_dsa", "~/.ssh/id_rsa"]
? n         l                       
===========================================================================================================================
F
===========================================================================================================================
Failure: <nil> is not true.
test_load_with_numeric_host(TestConfig)
./test_config.rb:110:in `test_load_with_numeric_host'
/usr/lib64/ruby/gems/1.8/gems/mocha-0.10.5/lib/mocha/integration/test_unit/gem_version_230_to_240.rb:25:in `run'
     22:             begin
     23:               begin
     24:                 run_setup
  => 25:                 run_test
     26:                 run_cleanup
     27:                 mocha_verify(assertion_counter)
     28:                 add_pass

Can't execute more than one command on Cisco device

I am writing a simple script to run two commands on a Cisco 4500 switch. I noticed that I am only able to execute a single command when I initiate an SSH connection with Net::SSH.start.

Here is my source code:

require 'net/ssh'

Net::SSH.start('hostname', username, :password => 'some_password') do |ssh|
  ssh.exec!("show run")
  channel = ssh.open_channel do |ch|
    ch.exec "show ip mroute count" do |ch, success|
      abort "Could not execute your command." unless success
      ch.on_data do |c, data|
        puts data
      end
    end
  end
end

The error I get is below:

C:\Users\ddyba\Scripts\Mscrape\lib>ruby mscrape.rb
C:/Users/ddyba/Programs/Ruby192/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/buffered_io.rb:99:in `send': closed stream (IOError)
        from C:/Users/ddyba/Programs/Ruby192/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/buffered_io.rb:99:in `send_pending'
        from C:/Users/ddyba/Programs/Ruby192/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/connection/session.rb:236:in `block in postprocess'
        from C:/Users/ddyba/Programs/Ruby192/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/connection/session.rb:235:in `each'
        from C:/Users/ddyba/Programs/Ruby192/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/connection/session.rb:235:in `postprocess'
        from C:/Users/ddyba/Programs/Ruby192/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/connection/session.rb:203:in `process'
        from C:/Users/ddyba/Programs/Ruby192/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/connection/session.rb:161:in `block in loop'
        from C:/Users/ddyba/Programs/Ruby192/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/connection/session.rb:161:in `loop'
        from C:/Users/ddyba/Programs/Ruby192/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/connection/session.rb:161:in `loop'
        from C:/Users/ddyba/Programs/Ruby192/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/connection/session.rb:110:in `close'
        from C:/Users/ddyba/Programs/Ruby192/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh.rb:191:in `start'
        from mscrape.rb:3:in `<main>'

I was reading the source code, but at my current Ruby skill level it's over my head. The problem goes away when I get rid of the commented line. More generally, I don't encounter any problems when I execute only one command.

require 'net/ssh'

Net::SSH.start('hostname', username, :password => 'some_password') do |ssh|
  # ssh.exec!("show run")
  channel = ssh.open_channel do |ch|
    ch.exec "show ip mroute count" do |ch, success|
      abort "Could not execute your command." unless success
      ch.on_data do |c, data|
        puts data
      end
    end
  end
end

could not verify server signature

Got a intermittent problem when I use net-ssh here is the debug output.

D, [2012-10-15T10:22:08.014848 #2463] DEBUG -- net.ssh.transport.session[bfcb24]: establishing connection to 192.168.100.102:22
D, [2012-10-15T10:22:08.015684 #2463] DEBUG -- net.ssh.transport.session[bfcb24]: connection established
I, [2012-10-15T10:22:08.015813 #2463] INFO -- net.ssh.transport.server_version[bfb6e8]: negotiating protocol version
D, [2012-10-15T10:22:08.022038 #2463] DEBUG -- net.ssh.transport.server_version[bfb6e8]: remote is SSH-2.0-1' D, [2012-10-15T10:22:08.022125 #2463] DEBUG -- net.ssh.transport.server_version[bfb6e8]: local isSSH-2.0-Ruby/Net::SSH_2.6.0 x86_64-linux'
D, [2012-10-15T10:22:08.022815 #2463] DEBUG -- tcpsocket[bfc23c]: read 344 bytes
D, [2012-10-15T10:22:08.022965 #2463] DEBUG -- tcpsocket[bfc23c]: received packet nr 0 type 20 len 340
I, [2012-10-15T10:22:08.023170 #2463] INFO -- net.ssh.transport.algorithms[bf5bd0]: got KEXINIT from server
I, [2012-10-15T10:22:08.023384 #2463] INFO -- net.ssh.transport.algorithms[bf5bd0]: sending KEXINIT
D, [2012-10-15T10:22:08.023572 #2463] DEBUG -- tcpsocket[bfc23c]: queueing packet nr 0 type 20 len 1620
D, [2012-10-15T10:22:08.023678 #2463] DEBUG -- tcpsocket[bfc23c]: sent 1624 bytes
I, [2012-10-15T10:22:08.023826 #2463] INFO -- net.ssh.transport.algorithms[bf5bd0]: negotiating algorithms
D, [2012-10-15T10:22:08.024101 #2463] DEBUG -- net.ssh.transport.algorithms[bf5bd0]: negotiated:

  • kex: diffie-hellman-group1-sha1
  • host_key: ssh-rsa
  • encryption_server: aes128-cbc
  • encryption_client: aes128-cbc
  • hmac_client: hmac-sha1
  • hmac_server: hmac-sha1
  • compression_client: none
  • compression_server: none
  • language_client:
  • language_server:
    D, [2012-10-15T10:22:08.024256 #2463] DEBUG -- net.ssh.transport.algorithms[bf5bd0]: exchanging keys
    D, [2012-10-15T10:22:08.025592 #2463] DEBUG -- tcpsocket[bfc23c]: queueing packet nr 1 type 30 len 140
    D, [2012-10-15T10:22:08.025688 #2463] DEBUG -- tcpsocket[bfc23c]: sent 144 bytes
    D, [2012-10-15T10:22:08.072246 #2463] DEBUG -- tcpsocket[bfc23c]: read 464 bytes
    D, [2012-10-15T10:22:08.072385 #2463] DEBUG -- tcpsocket[bfc23c]: received packet nr 1 type 31 len 444
    D, [2012-10-15T10:22:08.073516 #2463] DEBUG -- tcpsocket[bfc23c]: queueing packet nr 2 type 21 len 20
    D, [2012-10-15T10:22:08.073664 #2463] DEBUG -- tcpsocket[bfc23c]: sent 24 bytes
    D, [2012-10-15T10:22:08.073787 #2463] DEBUG -- tcpsocket[bfc23c]: received packet nr 2 type 21 len 12
    D, [2012-10-15T10:22:08.074101 #2463] DEBUG -- net.ssh.authentication.session[b364b0]: beginning authentication of admin' D, [2012-10-15T10:22:08.074254 #2463] DEBUG -- tcpsocket[bfc23c]: queueing packet nr 3 type 5 len 28 D, [2012-10-15T10:22:08.074340 #2463] DEBUG -- tcpsocket[bfc23c]: sent 52 bytes D, [2012-10-15T10:22:08.074904 #2463] DEBUG -- tcpsocket[bfc23c]: read 52 bytes D, [2012-10-15T10:22:08.075042 #2463] DEBUG -- tcpsocket[bfc23c]: received packet nr 3 type 6 len 28 D, [2012-10-15T10:22:08.075283 #2463] DEBUG -- net.ssh.authentication.session[b364b0]: trying none D, [2012-10-15T10:22:08.075408 #2463] DEBUG -- net.ssh.authentication.session[b364b0]: Mechanism none was requested, but isn't a known type. Ignoring it. D, [2012-10-15T10:22:08.075559 #2463] DEBUG -- net.ssh.authentication.session[b364b0]: trying publickey D, [2012-10-15T10:22:08.075895 #2463] DEBUG -- net.ssh.authentication.agent[b29cd8]: connecting to ssh-agent E, [2012-10-15T10:22:08.076055 #2463] ERROR -- net.ssh.authentication.agent[b29cd8]: could not connect to ssh-agent D, [2012-10-15T10:22:08.076268 #2463] DEBUG -- net.ssh.authentication.methods.publickey[b2bad8]: trying publickey (a0:9a:23:2b:de:a6:bd:d4:68:00:90:de:2d:30:f1:ce) D, [2012-10-15T10:22:08.076434 #2463] DEBUG -- tcpsocket[bfc23c]: queueing packet nr 4 type 50 len 508 D, [2012-10-15T10:22:08.076528 #2463] DEBUG -- tcpsocket[bfc23c]: sent 532 bytes D, [2012-10-15T10:22:08.077079 #2463] DEBUG -- tcpsocket[bfc23c]: read 68 bytes D, [2012-10-15T10:22:08.077204 #2463] DEBUG -- tcpsocket[bfc23c]: received packet nr 4 type 51 len 44 D, [2012-10-15T10:22:08.077378 #2463] DEBUG -- net.ssh.authentication.session[b364b0]: allowed methods: password,publickey D, [2012-10-15T10:22:08.077473 #2463] DEBUG -- net.ssh.authentication.session[b364b0]: trying password D, [2012-10-15T10:22:08.077618 #2463] DEBUG -- tcpsocket[bfc23c]: queueing packet nr 5 type 50 len 60 D, [2012-10-15T10:22:08.077711 #2463] DEBUG -- tcpsocket[bfc23c]: sent 84 bytes D, [2012-10-15T10:22:08.088561 #2463] DEBUG -- tcpsocket[bfc23c]: read 36 bytes D, [2012-10-15T10:22:08.088687 #2463] DEBUG -- tcpsocket[bfc23c]: received packet nr 5 type 52 len 12 D, [2012-10-15T10:22:08.088800 #2463] DEBUG -- net.ssh.authentication.methods.password[a50514]: password succeeded D, [2012-10-15T10:22:08.088976 #2463] DEBUG -- tcpsocket[bfc23c]: queueing packet nr 6 type 90 len 44 D, [2012-10-15T10:22:08.089112 #2463] DEBUG -- tcpsocket[bfc23c]: sent 68 bytes D, [2012-10-15T10:22:08.089758 #2463] DEBUG -- tcpsocket[bfc23c]: read 52 bytes D, [2012-10-15T10:22:08.090153 #2463] DEBUG -- tcpsocket[bfc23c]: received packet nr 6 type 91 len 28 I, [2012-10-15T10:22:08.090326 #2463] INFO -- net.ssh.connection.session[a49c28]: channel_open_confirmation: 0 2109207399 0 35000 I, [2012-10-15T10:22:08.090522 #2463] INFO -- net.ssh.connection.channel[a497dc]: sending channel request "exec" D, [2012-10-15T10:22:08.090687 #2463] DEBUG -- tcpsocket[bfc23c]: queueing packet nr 7 type 98 len 92 D, [2012-10-15T10:22:08.090815 #2463] DEBUG -- tcpsocket[bfc23c]: sent 116 bytes D, [2012-10-15T10:22:08.091551 #2463] DEBUG -- tcpsocket[bfc23c]: read 312 bytes D, [2012-10-15T10:22:08.091737 #2463] DEBUG -- tcpsocket[bfc23c]: received packet nr 7 type 94 len 28 I, [2012-10-15T10:22:08.091840 #2463] INFO -- net.ssh.connection.session[a49c28]: channel_data: 0 2b D, [2012-10-15T10:22:08.091975 #2463] DEBUG -- tcpsocket[bfc23c]: received packet nr 8 type 94 len 60 I, [2012-10-15T10:22:08.092073 #2463] INFO -- net.ssh.connection.session[a49c28]: channel_data: 0 35b D, [2012-10-15T10:22:08.092203 #2463] DEBUG -- tcpsocket[bfc23c]: received packet nr 9 type 94 len 28 I, [2012-10-15T10:22:08.096269 #2463] INFO -- net.ssh.connection.session[a49c28]: channel_data: 0 2b D, [2012-10-15T10:22:08.096532 #2463] DEBUG -- tcpsocket[bfc23c]: received packet nr 10 type 97 len 12 I, [2012-10-15T10:22:08.096633 #2463] INFO -- net.ssh.connection.session[a49c28]: channel_close: 0 D, [2012-10-15T10:22:08.096771 #2463] DEBUG -- tcpsocket[bfc23c]: queueing packet nr 8 type 97 len 28 D, [2012-10-15T10:22:08.096901 #2463] DEBUG -- tcpsocket[bfc23c]: received packet nr 11 type 93 len 28 I, [2012-10-15T10:22:08.096998 #2463] INFO -- net.ssh.connection.session[a49c28]: channel_window_adjust: 0 +10240 W, [2012-10-15T10:22:08.097086 #2463] WARN -- net.ssh.connection.session[a49c28]: ignoring request :do_window_adjust for non-existent (closed?) channel; probably ssh server bug D, [2012-10-15T10:22:08.097274 #2463] DEBUG -- tcpsocket[bfc23c]: received packet nr 12 type 99 len 12 I, [2012-10-15T10:22:08.097375 #2463] INFO -- net.ssh.connection.session[a49c28]: channel_success: 0 W, [2012-10-15T10:22:08.097454 #2463] WARN -- net.ssh.connection.session[a49c28]: ignoring request :do_success for non-existent (closed?) channel; probably ssh server bug I, [2012-10-15T10:22:13.097700 #2463] INFO -- net.ssh.connection.session[a49c28]: closing remaining channels (0 open) D, [2012-10-15T10:22:13.098706 #2463] DEBUG -- net.ssh.transport.session[bb8b68]: establishing connection to 192.168.100.102:22 D, [2012-10-15T10:22:13.099252 #2463] DEBUG -- net.ssh.transport.session[bb8b68]: connection established I, [2012-10-15T10:22:13.099434 #2463] INFO -- net.ssh.transport.server_version[bbd8e8]: negotiating protocol version D, [2012-10-15T10:22:13.101658 #2463] DEBUG -- net.ssh.transport.server_version[bbd8e8]: remote isSSH-2.0-1'
    D, [2012-10-15T10:22:13.101742 #2463] DEBUG -- net.ssh.transport.server_version[bbd8e8]: local is `SSH-2.0-Ruby/Net::SSH_2.6.0 x86_64-linux'
    D, [2012-10-15T10:22:13.102567 #2463] DEBUG -- tcpsocket[bbc95c]: read 344 bytes
    D, [2012-10-15T10:22:13.102702 #2463] DEBUG -- tcpsocket[bbc95c]: received packet nr 0 type 20 len 340
    I, [2012-10-15T10:22:13.102865 #2463] INFO -- net.ssh.transport.algorithms[bd22d4]: got KEXINIT from server
    I, [2012-10-15T10:22:13.103038 #2463] INFO -- net.ssh.transport.algorithms[bd22d4]: sending KEXINIT
    D, [2012-10-15T10:22:13.103263 #2463] DEBUG -- tcpsocket[bbc95c]: queueing packet nr 0 type 20 len 1620
    D, [2012-10-15T10:22:13.103418 #2463] DEBUG -- tcpsocket[bbc95c]: sent 1624 bytes
    I, [2012-10-15T10:22:13.103505 #2463] INFO -- net.ssh.transport.algorithms[bd22d4]: negotiating algorithms
    D, [2012-10-15T10:22:13.103748 #2463] DEBUG -- net.ssh.transport.algorithms[bd22d4]: negotiated:
  • kex: diffie-hellman-group1-sha1
  • host_key: ssh-rsa
  • encryption_server: aes128-cbc
  • encryption_client: aes128-cbc
  • hmac_client: hmac-sha1
  • hmac_server: hmac-sha1
  • compression_client: none
  • compression_server: none
  • language_client:
  • language_server:
    D, [2012-10-15T10:22:13.103839 #2463] DEBUG -- net.ssh.transport.algorithms[bd22d4]: exchanging keys
    D, [2012-10-15T10:22:13.105041 #2463] DEBUG -- tcpsocket[bbc95c]: queueing packet nr 1 type 30 len 140
    D, [2012-10-15T10:22:13.105140 #2463] DEBUG -- tcpsocket[bbc95c]: sent 144 bytes
    D, [2012-10-15T10:22:13.152417 #2463] DEBUG -- tcpsocket[bbc95c]: read 464 bytes
    D, [2012-10-15T10:22:13.152558 #2463] DEBUG -- tcpsocket[bbc95c]: received packet nr 1 type 31 len 444
    D, [2012-10-15T10:22:13.153556 #2463] DEBUG -- tcpsocket[bbc95c]: queueing packet nr 2 type 21 len 20
    D, [2012-10-15T10:22:13.153654 #2463] DEBUG -- tcpsocket[bbc95c]: sent 24 bytes
    D, [2012-10-15T10:22:13.153795 #2463] DEBUG -- tcpsocket[bbc95c]: received packet nr 2 type 21 len 12
    D, [2012-10-15T10:22:13.154127 #2463] DEBUG -- net.ssh.authentication.session[bfc944]: beginning authentication of admin' D, [2012-10-15T10:22:13.154335 #2463] DEBUG -- tcpsocket[bbc95c]: queueing packet nr 3 type 5 len 28 D, [2012-10-15T10:22:13.154457 #2463] DEBUG -- tcpsocket[bbc95c]: sent 52 bytes D, [2012-10-15T10:22:13.154810 #2463] DEBUG -- tcpsocket[bbc95c]: read 52 bytes D, [2012-10-15T10:22:13.155014 #2463] DEBUG -- tcpsocket[bbc95c]: received packet nr 3 type 6 len 28 D, [2012-10-15T10:22:13.155182 #2463] DEBUG -- net.ssh.authentication.session[bfc944]: trying none D, [2012-10-15T10:22:13.155303 #2463] DEBUG -- net.ssh.authentication.session[bfc944]: Mechanism none was requested, but isn't a known type. Ignoring it. D, [2012-10-15T10:22:13.155416 #2463] DEBUG -- net.ssh.authentication.session[bfc944]: trying publickey D, [2012-10-15T10:22:13.155715 #2463] DEBUG -- net.ssh.authentication.agent[be8ebc]: connecting to ssh-agent E, [2012-10-15T10:22:13.155831 #2463] ERROR -- net.ssh.authentication.agent[be8ebc]: could not connect to ssh-agent D, [2012-10-15T10:22:13.156087 #2463] DEBUG -- net.ssh.authentication.methods.publickey[beeb78]: trying publickey (a0:9a:23:2b:de:a6:bd:d4:68:00:90:de:2d:30:f1:ce) D, [2012-10-15T10:22:13.156257 #2463] DEBUG -- tcpsocket[bbc95c]: queueing packet nr 4 type 50 len 508 D, [2012-10-15T10:22:13.156352 #2463] DEBUG -- tcpsocket[bbc95c]: sent 532 bytes D, [2012-10-15T10:22:13.156906 #2463] DEBUG -- tcpsocket[bbc95c]: read 68 bytes D, [2012-10-15T10:22:13.157059 #2463] DEBUG -- tcpsocket[bbc95c]: received packet nr 4 type 51 len 44 D, [2012-10-15T10:22:13.157203 #2463] DEBUG -- net.ssh.authentication.session[bfc944]: allowed methods: password,publickey D, [2012-10-15T10:22:13.157287 #2463] DEBUG -- net.ssh.authentication.session[bfc944]: trying password D, [2012-10-15T10:22:13.157432 #2463] DEBUG -- tcpsocket[bbc95c]: queueing packet nr 5 type 50 len 60 D, [2012-10-15T10:22:13.157525 #2463] DEBUG -- tcpsocket[bbc95c]: sent 84 bytes D, [2012-10-15T10:22:13.168417 #2463] DEBUG -- tcpsocket[bbc95c]: read 36 bytes D, [2012-10-15T10:22:13.168550 #2463] DEBUG -- tcpsocket[bbc95c]: received packet nr 5 type 52 len 12 D, [2012-10-15T10:22:13.168675 #2463] DEBUG -- net.ssh.authentication.methods.password[b6e018]: password succeeded D, [2012-10-15T10:22:13.168860 #2463] DEBUG -- tcpsocket[bbc95c]: queueing packet nr 6 type 90 len 44 D, [2012-10-15T10:22:13.169005 #2463] DEBUG -- tcpsocket[bbc95c]: sent 68 bytes D, [2012-10-15T10:22:13.169474 #2463] DEBUG -- tcpsocket[bbc95c]: read 52 bytes D, [2012-10-15T10:22:13.169614 #2463] DEBUG -- tcpsocket[bbc95c]: received packet nr 6 type 91 len 28 I, [2012-10-15T10:22:13.169754 #2463] INFO -- net.ssh.connection.session[b5a194]: channel_open_confirmation: 0 941489098 0 35000 I, [2012-10-15T10:22:13.169863 #2463] INFO -- net.ssh.connection.channel[b59d98]: sending channel request "exec" D, [2012-10-15T10:22:13.170060 #2463] DEBUG -- tcpsocket[bbc95c]: queueing packet nr 7 type 98 len 44 D, [2012-10-15T10:22:13.170181 #2463] DEBUG -- tcpsocket[bbc95c]: sent 68 bytes D, [2012-10-15T10:22:13.422562 #2463] DEBUG -- tcpsocket[bbc95c]: read 412 bytes D, [2012-10-15T10:22:13.422748 #2463] DEBUG -- tcpsocket[bbc95c]: received packet nr 7 type 94 len 28 I, [2012-10-15T10:22:13.422862 #2463] INFO -- net.ssh.connection.session[b5a194]: channel_data: 0 2b D, [2012-10-15T10:22:13.423060 #2463] DEBUG -- tcpsocket[bbc95c]: received packet nr 8 type 94 len 60 I, [2012-10-15T10:22:13.423166 #2463] INFO -- net.ssh.connection.session[b5a194]: channel_data: 0 45b D, [2012-10-15T10:22:13.423297 #2463] DEBUG -- tcpsocket[bbc95c]: received packet nr 9 type 94 len 76 I, [2012-10-15T10:22:13.423446 #2463] INFO -- net.ssh.connection.session[b5a194]: channel_data: 0 51b D, [2012-10-15T10:22:13.423587 #2463] DEBUG -- tcpsocket[bbc95c]: received packet nr 10 type 94 len 28 I, [2012-10-15T10:22:13.423684 #2463] INFO -- net.ssh.connection.session[b5a194]: channel_data: 0 2b D, [2012-10-15T10:22:13.423807 #2463] DEBUG -- tcpsocket[bbc95c]: received packet nr 11 type 97 len 12 I, [2012-10-15T10:22:13.423899 #2463] INFO -- net.ssh.connection.session[b5a194]: channel_close: 0 D, [2012-10-15T10:22:13.424024 #2463] DEBUG -- tcpsocket[bbc95c]: queueing packet nr 8 type 97 len 28 D, [2012-10-15T10:22:13.424149 #2463] DEBUG -- tcpsocket[bbc95c]: received packet nr 12 type 93 len 28 I, [2012-10-15T10:22:13.424240 #2463] INFO -- net.ssh.connection.session[b5a194]: channel_window_adjust: 0 +10240 W, [2012-10-15T10:22:13.424322 #2463] WARN -- net.ssh.connection.session[b5a194]: ignoring request :do_window_adjust for non-existent (closed?) channel; probably ssh server bug D, [2012-10-15T10:22:13.424441 #2463] DEBUG -- tcpsocket[bbc95c]: received packet nr 13 type 99 len 12 I, [2012-10-15T10:22:13.424530 #2463] INFO -- net.ssh.connection.session[b5a194]: channel_success: 0 W, [2012-10-15T10:22:13.424602 #2463] WARN -- net.ssh.connection.session[b5a194]: ignoring request :do_success for non-existent (closed?) channel; probably ssh server bug I, [2012-10-15T10:22:33.424840 #2463] INFO -- net.ssh.connection.session[b5a194]: closing remaining channels (0 open) D, [2012-10-15T10:22:33.425529 #2463] DEBUG -- net.ssh.transport.session[a57a80]: establishing connection to 192.168.100.102:22 D, [2012-10-15T10:22:33.427011 #2463] DEBUG -- net.ssh.transport.session[a57a80]: connection established I, [2012-10-15T10:22:33.427148 #2463] INFO -- net.ssh.transport.server_version[a556a4]: negotiating protocol version D, [2012-10-15T10:22:33.430160 #2463] DEBUG -- net.ssh.transport.server_version[a556a4]: remote isSSH-2.0-1'
    D, [2012-10-15T10:22:33.430248 #2463] DEBUG -- net.ssh.transport.server_version[a556a4]: local is `SSH-2.0-Ruby/Net::SSH_2.6.0 x86_64-linux'
    D, [2012-10-15T10:22:33.430989 #2463] DEBUG -- tcpsocket[a56af4]: read 344 bytes
    D, [2012-10-15T10:22:33.431128 #2463] DEBUG -- tcpsocket[a56af4]: received packet nr 0 type 20 len 340
    I, [2012-10-15T10:22:33.431244 #2463] INFO -- net.ssh.transport.algorithms[a4df6c]: got KEXINIT from server
    I, [2012-10-15T10:22:33.431468 #2463] INFO -- net.ssh.transport.algorithms[a4df6c]: sending KEXINIT
    D, [2012-10-15T10:22:33.431677 #2463] DEBUG -- tcpsocket[a56af4]: queueing packet nr 0 type 20 len 1620
    D, [2012-10-15T10:22:33.431788 #2463] DEBUG -- tcpsocket[a56af4]: sent 1624 bytes
    I, [2012-10-15T10:22:33.431872 #2463] INFO -- net.ssh.transport.algorithms[a4df6c]: negotiating algorithms
    D, [2012-10-15T10:22:33.432107 #2463] DEBUG -- net.ssh.transport.algorithms[a4df6c]: negotiated:
  • kex: diffie-hellman-group1-sha1
  • host_key: ssh-rsa
  • encryption_server: aes128-cbc
  • encryption_client: aes128-cbc
  • hmac_client: hmac-sha1
  • hmac_server: hmac-sha1
  • compression_client: none
  • compression_server: none
  • language_client:
  • language_server:
    D, [2012-10-15T10:22:33.432199 #2463] DEBUG -- net.ssh.transport.algorithms[a4df6c]: exchanging keys
    D, [2012-10-15T10:22:33.436929 #2463] DEBUG -- tcpsocket[a56af4]: queueing packet nr 1 type 30 len 140
    D, [2012-10-15T10:22:33.437117 #2463] DEBUG -- tcpsocket[a56af4]: sent 144 bytes
    D, [2012-10-15T10:22:33.483868 #2463] DEBUG -- tcpsocket[a56af4]: read 464 bytes
    D, [2012-10-15T10:22:33.484018 #2463] DEBUG -- tcpsocket[a56af4]: received packet nr 1 type 31 len 444
    /var/lib/gems/1.9.1/gems/net-ssh-2.6.0/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb:196:in verify_signature': could not verify server signature (Net::SSH::Exception) from /var/lib/gems/1.9.1/gems/net-ssh-2.6.0/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb:69:inexchange_keys'
    from /var/lib/gems/1.9.1/gems/net-ssh-2.6.0/lib/net/ssh/transport/algorithms.rb:355:in exchange_keys' from /var/lib/gems/1.9.1/gems/net-ssh-2.6.0/lib/net/ssh/transport/algorithms.rb:196:inproceed!'
    from /var/lib/gems/1.9.1/gems/net-ssh-2.6.0/lib/net/ssh/transport/algorithms.rb:187:in send_kexinit' from /var/lib/gems/1.9.1/gems/net-ssh-2.6.0/lib/net/ssh/transport/algorithms.rb:142:inaccept_kexinit'
    from /var/lib/gems/1.9.1/gems/net-ssh-2.6.0/lib/net/ssh/transport/session.rb:189:in block in poll_message' from /var/lib/gems/1.9.1/gems/net-ssh-2.6.0/lib/net/ssh/transport/session.rb:167:inloop'
    from /var/lib/gems/1.9.1/gems/net-ssh-2.6.0/lib/net/ssh/transport/session.rb:167:in poll_message' from /var/lib/gems/1.9.1/gems/net-ssh-2.6.0/lib/net/ssh/transport/session.rb:204:inblock in wait'
    from /var/lib/gems/1.9.1/gems/net-ssh-2.6.0/lib/net/ssh/transport/session.rb:202:in loop' from /var/lib/gems/1.9.1/gems/net-ssh-2.6.0/lib/net/ssh/transport/session.rb:202:inwait'
    from /var/lib/gems/1.9.1/gems/net-ssh-2.6.0/lib/net/ssh/transport/session.rb:81:in initialize' from /var/lib/gems/1.9.1/gems/net-ssh-2.6.0/lib/net/ssh.rb:186:innew'
    from /var/lib/gems/1.9.1/gems/net-ssh-2.6.0/lib/net/ssh.rb:186:in `start'

Broken on Windows with Ruby 2.0.0

There is a problem due to hardcoded checks for version 1.9 of ruby on the code.

.../lib/ruby/gems/2.0.0/gems/net-ssh-2.6.2/lib/net/ssh/authentication/pageant.rb:45:in `<module:Win>': undefined method `typealias' for Net::SSH::Authentication::Pageant::Win:Module (NoMethodError)

I suppose the best approach is to assume the api will not change upwards, when it does it should be fixed. Instead of supporting only a few specific versions and having to fix everytime a new version is released.

I fixed locally and it seems fine, though I haven't run any tests.
I'll fork and apply my fix, if tests are ok I'll make a pull request.

Document advantages over shelling out

Can you add something to the README that describes a few examples of when you need a pure Ruby implementation instead of just using the system ssh ?

No biggie, just thought it'd be cool if it mentioned a few to get the brainstorming going.

Proxy with SSH instance instead of command line string

I wish there was a way to create an SSH connection, then use that connection as the proxy object, instead of having to use a command line string.

For example, currently, you need to do something like the following:
proxy = Net::SSH::Proxy::Command.new('ssh -e none other-host nc %h %p') Net::SSH.start('host', 'user', :proxy => proxy) do |ssh| ... end

Whereas I wish we could do something like the following:
connection = Net::SSH.start('other-host', username, :password => passwd) proxy = Net::SSH::Proxy::Connection.new(connection) Net::SSH.start('host', 'user', :password => proxy_passwd, :proxy => proxy)

Net::SSH.start doesn't throw any exceptions

Using the following code (in a Sinatra app), no exception is raised:

begin
  @session = Net::SSH.start('no-host', 'no-user', keys: [])
rescue SocketError => e
  logger.error "SOCKET ERROR: "+e.message
rescue Net::SSH::AuthenticationFailed => e
  logger.error "AUTH ERROR: "+e.message
rescue Exception => e
  logger.error "EXCEPTION: "+e.message
end

However in irb, an exception is raised:

> require 'net/ssh'
> Net::SSH.start('no-host', 'no-user', keys: [])
= SocketError: getaddrinfo: nodename nor servname provided, or not known

I'm using Ruby 1.9.3-p194 and the latest version of Net::SSH(2.4.0)

is there a good way to interactive with a ssh-based BBS with ruby net-ssh ?

require 'net/ssh'
  Net::SSH.start('ptt.cc', 'bbsu',:password=>'a') do |ssh|
end

I want to interactive with this site. after I see a login page, I don't know how to send any key to this host. ex: I can send new and maybe with a newline. Then , I can see a new member page . And if I see, I will press some key .

I've try to reading manual, trying using channel, but still can't figure out a good way. Could somebody help me ? thanks.

Remote and Local Forward

Hi!

Net::SSH.configuration_for ignore LocalForward and RemoteForward from ~/.ssh/config and Net::SSH.start has no option for forward

NET::SSH tries all keys from agent before specified keys

I seems that NET::SSH.start(..., :keys => [list of keys]) is trying all keys from the agent before trying the keys specified in the :keys option.

Default configuration of many SSH servers it to abort the connection after a few failed auth attempts (e.g. 3 or 5). As a result, if too many keys are tried before trying the right one, the connection is aborted. I have more than 5 keys in my ~/.ssh, all of them are tried before trying the keys I specified, and as a result NET::SSH.start is not working anymore for me.

Here is a stripped-down script I used to test this:

#!/usr/bin/ruby

require 'rubygems'
require 'net/ssh'

Net::SSH.start('hostname', 'user', :verbose => Logger::DEBUG, :keys => ['~/id_rsa']) do |ssh|
  output = ssh.exec!("hostname")
  puts output
end

The bug seems to come from KeyManager.each_identify, which is returning keys from the agent before user specified keys.

I'm using net-ssh 2.1.4

Test failure with net-ssh 2.5.2 on ruby 1.8

With ruby 1.8.7 (2012-06-29 patchlevel 370) [x86_64-linux] I'm getting the following test failure:

Failure:
test_key_for_when_all_hosts_are_recognized(TestKnownHosts)
./test_known_hosts.rb:9:in `test_key_for_when_all_hosts_are_recognized'
/usr/lib64/ruby/gems/1.8/gems/mocha-0.12.3/lib/mocha/integration/test_unit/gem_version_230_to_251.rb:25:in `run'
     22:             begin
     23:               begin
     24:                 run_setup
  => 25:                 run_test
     26:                 run_cleanup
     27:                 mocha_verify(assertion_counter)
     28:                 add_pass
<1> expected but was
<0>

diff:
? 1
? 0

Test suite errors with Ruby 2.0.0

There is plenty errors such as:

===============================================================================
Failure:
test_from_should_build_new_buffer_from_definition(TestBuffer)
/builddir/build/BUILD/rubygem-net-ssh-2.6.6/usr/share/gems/gems/net-ssh-2.6.6/test/test_buffer.rb:24:in `test_from_should_build_new_buffer_from_definition'
     21: 
     22:   def test_from_should_build_new_buffer_from_definition
     23:     buffer = Net::SSH::Buffer.from(:byte, 1, :long, 2, :int64, 3, :string, "4", :bool, true, :bool, false, :bignum, OpenSSL::BN.new("1234567890", 10), :raw, "something")
  => 24:     assert_equal "\1\0\0\0\2\0\0\0\0\0\0\0\3\0\0\0\0014\1\0\000\000\000\004I\226\002\322something", buffer.to_s
     25:   end
     26: 
     27:   def test_from_with_array_argument_should_write_multiple_of_the_given_type
<"\u0001\0\0\0\u0002\0\0\0\0\0\0\0\u0003\0\0\0\u00014\u0001\0\0\0\0\u0004I\x96\u0002\xD2something">(UTF-8) expected but was
<"\x01\0\0\0\x02\0\0\0\0\0\0\0\x03\0\0\0\x014\x01\0\0\0\0\x04I\x96\x02\xD2something">(ASCII-8BIT)
diff:


? Encoding: UTF  -8   
?           ASCII  BIT         

running with Ruby 2.0.0. Adding # encoding: ASCII-8BIT on top of test/test_buffer.rb fixes the errors. Not sure if that is correct approach, though.

AgentError, unknown response from agent on Windows with 64-bit PuTTY

Originally reported in vagrant, net-ssh appears to be subject to the same issue reported in Paramiko when querying the PAgeant across different UAC contexts.

I was the author of the fix for Paramiko, which involved invoking the Windows APIs to set the security attributes on the memory-mapped file used to communicate across contexts much as the reference PuTTY implementation does.

I'm not a Ruby dev, so wouldn't know where to start with a fix, so I'm hoping someone else will pick this up and develop a fix. Please feel free to tap me if I can provide help in devising a fix.

Known issues with dropbear?

I am using net-ssh to communicate with a dropbear server v0.53.1 - sometimes it seems not to close the ssh-connection properly.

Using a normal ssh client on my system the end of a connection looks like this:

TRACE (2653): writebuf size 0 extrabuf size 0
TRACE (2653): sesscheckclose, pid is 1074607552
TRACE (2653): enter remove_channel
TRACE (2653): channel index is 0
TRACE (2653): CLOSE writefd -1
TRACE (2653): CLOSE readfd -1
TRACE (2653): CLOSE errfd -1
TRACE (2653): leave remove_channel
TRACE (2653): leave recv_msg_channel_close
TRACE (2653): leave process_packet
TRACE (2653): enter read_packet
TRACE (2653): packet size is 64, block 16 mac 16
TRACE (2653): enter decrypt_packet
TRACE (2653): enter writemac
TRACE (2653): leave writemac
TRACE (2653): leave decrypt_packet
TRACE (2653): leave read_packet
TRACE (2653): enter process_packet
TRACE (2653): process_packet: packet type = 1
[2653] Aug 31 11:07:36 Exit (root): Disconnect received
TRACE (2653): enter session_cleanup
TRACE (2653): enter chancleanup
TRACE (2653): leave chancleanup
TRACE (2653): leave session_cleanup

If I am using net-ssh from time to time the connection seems to freeze. And the last thing I get is the following:

TRACE (2951): leave setnonblocking
TRACE (2951): setnonblocking: 12
TRACE (2951): leave setnonblocking
TRACE (2951): setnonblocking: 15
TRACE (2951): leave setnonblocking
TRACE (2951): leave noptycommand
TRACE (2951): leave chansessionrequest
TRACE (2951): leave recv_msg_channel_request
TRACE (2951): leave process_packet
TRACE (2951): check_close: writefd 12, readfd 13, errfd 15, sent_close 0, recv_close 0
TRACE (2951): writebuf size 0 extrabuf size 0
TRACE (2951): sesscheckclose, pid is -1
TRACE (2951): sesscheckclose, pid is -1
TRACE (2951): enter read_packet
TRACE (2951): packet size is 52, block 16 mac 20
TRACE (2951): enter decrypt_packet
TRACE (2951): enter writemac
TRACE (2951): leave writemac
TRACE (2951): leave decrypt_packet
TRACE (2951): leave read_packet
TRACE (2951): enter process_packet
TRACE (2951): process_packet: packet type = 96
TRACE (2951): enter recv_msg_channel_eof
TRACE (2951): check_close: writefd 12, readfd 13, errfd 15, sent_close 0, recv_close 0
TRACE (2951): writebuf size 0 extrabuf size 0
TRACE (2951): sesscheckclose, pid is -1
TRACE (2951): sesscheckclose, pid is -1
TRACE (2951): CLOSE some fd 12
TRACE (2951): leave recv_msg_channel_eof
TRACE (2951): leave process_packet
TRACE (2951): send normal errfd
TRACE (2951): enter send_msg_channel_data
TRACE (2951): enter send_msg_channel_data isextended 1 fd 15
TRACE (2951): maxlen 16371
TRACE (2951): enter encrypt_packet()
TRACE (2951): encrypt_packet type is 95
TRACE (2951): enter writemac
TRACE (2951): leave writemac
TRACE (2951): enter enqueue
TRACE (2951): leave enqueue
TRACE (2951): leave encrypt_packet()
TRACE (2951): leave send_msg_channel_data
TRACE (2951): check_close: writefd -1, readfd 13, errfd 15, sent_close 0, recv_close 0
TRACE (2951): writebuf size 0 extrabuf size 0
TRACE (2951): sesscheckclose, pid is -1
TRACE (2951): sesscheckclose, pid is -1
TRACE (2951): CLOSE some fd -1
TRACE (2951): enter write_packet
TRACE (2951): empty queue dequeing
TRACE (2951): leave write_packet
TRACE (2951): check_close: writefd -1, readfd 13, errfd 15, sent_close 0, recv_close 0
TRACE (2951): writebuf size 0 extrabuf size 0
TRACE (2951): sesscheckclose, pid is -1
TRACE (2951): sesscheckclose, pid is -1
TRACE (2951): CLOSE some fd -1

I am really not a ssh expert. Does anybody have an idea what could have happend or how I could fix this problem?
If I should send you more output/logs please tell me.

Net:SSH problem with open_channel (Ruby 1.8.7)

submitted by: Matthew Mucklo
from: http://redmine.ruby-lang.org/issues/show/1041

It appears that the open_channel method does not always work when used without passing it a block.

Steps to reproduce:

require 'net/ssh'
ssh = Net::SSH.start('system', 'user', :password => 'password')
ch = ssh.open_channel
ch.exec 'ls' do |ch, success|
end

Resultant error:

TypeError: can't convert nil into Integer
from /usr/lib/ruby/site_ruby/1.8/net/ssh/buffer.rb:294:in `pack'
from /usr/lib/ruby/site_ruby/1.8/net/ssh/buffer.rb:294:in `write_long'
from /usr/lib/ruby/site_ruby/1.8/net/ssh/buffer.rb:55:in `send'
from /usr/lib/ruby/site_ruby/1.8/net/ssh/buffer.rb:55:in `from'
from /usr/lib/ruby/site_ruby/1.8/net/ssh/buffer.rb:47:in `step'
from /usr/lib/ruby/site_ruby/1.8/net/ssh/buffer.rb:47:in `from'
from /usr/lib/ruby/site_ruby/1.8/net/ssh/connection/channel.rb:465:in `send_channel_request'
from /usr/lib/ruby/site_ruby/1.8/net/ssh/connection/channel.rb:159:in `exec'
from (irb):9

The same does work if open_channel is passed a block, however, like such:

require 'net/ssh'
ssh = Net::SSH.start('system', 'user', :password => 'password')
channel = ssh.open_channel do |ch|
  ch.exec 'ls' do |ch, success|
  end
end

Also it will work if you run ssh.exec! before running ch.exec:

require 'net/ssh'
ssh = Net::SSH.start('system', 'user', :password => 'password')
ch = ssh.open_channel
ssh.exec! 'ls'
ch.exec 'ls' do |ch, success|
end

$ ruby -v
ruby 1.8.7 (2008-06-20 patchlevel 22) [ia64-hpux11.23]
$ uname -a
HP-UX srvr B.11.23 U ia64 4026996514 unlimited-user license

srvr is the name of the server

Net::SSH::Server?

This isnt so much an issue as a feature request, but i'm wondering what it would take to have net-ssh listen for inbound connections? Is this feasible or planned at some point in the future? I'd be quite happy with it simply using the none auth method and not having to deal with authentication so long as it could accept incoming SSH connections even as a single channel. Thanks much

Issue with IBN java 1.6 on AIX

Environment details :

OS: AIX 5.3
Java : IBM java 1.6
Jruby : 1.6.7.2

Issue : After a successful connection to the Host the thread used to hung for ever. I have investigate the issue through net-ssh gem , I found in the file "./net-ssh/gems/net-ssh-2.5.2/lib/net\ssh/connection/session.rb " , the process get hung at line number 225 , which is through the method def postprocess(readers, writers). I just tried with commet out the if condition with respective else condtion , all the thread connected successfully and works fine. even I tried without comment that if block in different OS using java 1.5 and java 1.6 , where as it never tried to execute that if block or else if

I guess that code may use for multithreading socket handeling . But I never exprienced if that block is used any way , and not sure why is it just hung in IBM java 1.6 . Please look into the issue and suggest the possible work around

affect code from "./net-ssh/gems/net-ssh-2.5.2/lib/net\ssh/connection/session.rb

def postprocess(readers, writers)
Array(readers).each do |reader|
if listeners[reader]----------------------------------------line No 225 , here it just hung for ever.
listeners[reader].call(reader)
else
if reader.fill.zero?
reader.close
stop_listening_to(reader)
end
end
end

  Array(writers).each do |writer|
    writer.send_pending
  end

  transport.rekey_as_needed

  return true
end

Thanks
Khirod

integrate AES CTR modes and arcfour(|128|256) support

from: http://rubyforge.org/tracker/?func=detail&group_id=274&aid=23742&atid=1123

the recent SSH protocol 2 vulnerability as reported in CPNI-957037:

http://www.cpni.gov.uk/Docs/Vulnerability_Advisory_SSH.txt

explains that there are inherent security issues in how CBC modes are used with the SSH protocol 2. While the attack
is difficult to mount its outcome may be serious, depending on the environment CBC cipher modes are used in. I can see
in algorithms.rb that net-ssh doesn't support anything aside from CBC modes:

  :encryption  => %w(aes128-cbc 3des-cbc blowfish-cbc cast128-cbc
                     aes192-cbc aes256-cbc [email protected]
                     idea-cbc none

we plan to remove CBC modes from the default server list in SSH in OpenSolaris (while keeping all modes on the client
side) since that's the only way to force the existing clients that usually have aes128-cbc as the first cipher to use
AES-CTR or arcfour. As a part of the move we looked at the situation of existing SSH client implementation and found
only 3 that don't support AES-CTR nor arcfour variants. Net-ssh is one of them (another one is pssh and SSH client shipped
with Cisco IOS). We can also see that several active SSH implementations added AES-CTR modes as a reaction to the advisory
released while other changing the ordering to prefer CTR modes.

we suggest the net-ssh project team to consider implementing AES-CTR and arcfour modes into net-ssh.

for more information, see RFC 4253 (arcfour), 4344 (AES-CTR), and 4345 (arcfour128, arcfour256).

Jan Pechanec (jan dot pechanec at sun dot com)

Unclear exception thrown

submitted by: Marijn Meijles
from: http://rubyforge.org/tracker/?func=detail&group_id=274&aid=23999&atid=1123

We regularly get the folllowing exception and stacktrace:

undefined method `any?' for nil:NilClass

/usr/lib/ruby/gems/1.8/gems/net-sftp-2.0.1/lib/net/sftp/session.rb:800:in `loop'
/usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.4/lib/net/ssh/connection/session.rb:193:in `preprocess'
/usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.4/lib/net/ssh/connection/session.rb:178:in `process'
/usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.4/lib/net/ssh/connection/session.rb:142:in `loop'
/usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.4/lib/net/ssh/connection/session.rb:142:in `loop_forever'
/usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.4/lib/net/ssh/connection/session.rb:142:in `loop'
/usr/lib/ruby/gems/1.8/gems/net-sftp-2.0.1/lib/net/sftp/session.rb:801:in `loop'
/usr/lib/ruby/gems/1.8/gems/net-sftp-2.0.1/lib/net/sftp.rb:34:in `start'

which, as far as I can see, is caused by the sftp server not having sent a version packet thereby skipping initialization of some instance vars. Is this correct? And if it's correct, wouldn't it be better to throw a more sensiible exception?

Connection hangs on ServerVersion.new(socket, logger)

Sometimes, when the server my script is connecting to does not answer correct the complete script hangs. I discovered this behaviour nearly a year ago. The version I use is 2.0.15.
I found this fix to resolve the issue for me:

--- session.rb.orig     2010-10-12 10:28:22.000000000 +0200
+++ session.rb  2010-10-12 10:27:36.000000000 +0200
@@ -72,7 +72,7 @@

       @host_key_verifier = select_host_key_verifier(options[:paranoid])

-      @server_version = ServerVersion.new(socket, logger)
+      @server_version = timeout(options[:timeout] || 0) { ServerVersion.new(socket, logger) }

       @algorithms = Algorithms.new(self, options)
       wait { algorithms.initialized? }

I'm not quite sure if the problem persists with the current release. And I'm not able to test it at the moment.

PasswordAuthentication in ssh_config excludes all other auth methods

submitted by: Jamis Buck
from: http://rubyforge.org/tracker/index.php?func=detail&aid=23904&group_id=274&atid=1123

If PasswordAuthentication (or PubkeyAuthentication) is set in ssh_config, all other authentication methods are excluded. This means setting PasswordAuthentication to "yes" will cause authentication to skip public key auth, unless it too is explicitly enabled. The default for openssh is for certain auth methods to default to "yes" (such as PubkeyAuthentication), and Net::SSH should follow that same pattern.

Net::SSH doesn't work if a proxy takes a %r

Apparently, proxy commands, according to SSHd, can have a %r for where to pass the user name. Net::SSH doesn't support this and fails.

ruby-1.9.2-p290 :004 > Net::SSH.start('example.net', 'ec2-user') {|ssh| p ssh }
ArgumentError: unknown key: r
from /home/natwelch/.rvm/gems/ruby-1.9.2-p290/gems/net-ssh-2.2.0/lib/net/ssh/proxy/command.rb:46:in `block in open'
from /home/natwelch/.rvm/gems/ruby-1.9.2-p290/gems/net-ssh-2.2.0/lib/net/ssh/proxy/command.rb:37:in `gsub'
from /home/natwelch/.rvm/gems/ruby-1.9.2-p290/gems/net-ssh-2.2.0/lib/net/ssh/proxy/command.rb:37:in `open'
from /home/natwelch/.rvm/gems/ruby-1.9.2-p290/gems/net-ssh-2.2.0/lib/net/ssh/transport/session.rb:66:in `block in initialize'
from /home/natwelch/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/timeout.rb:44:in `timeout'
from /home/natwelch/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/timeout.rb:89:in `timeout'
from /home/natwelch/.rvm/gems/ruby-1.9.2-p290/gems/net-ssh-2.2.0/lib/net/ssh/transport/session.rb:66:in `initialize'
from /home/natwelch/.rvm/gems/ruby-1.9.2-p290/gems/net-ssh-2.2.0/lib/net/ssh.rb:186:in `new'
from /home/natwelch/.rvm/gems/ruby-1.9.2-p290/gems/net-ssh-2.2.0/lib/net/ssh.rb:186:in `start'
from (irb):4
from /home/natwelch/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'

This happens because my work puts the following in my ssh_config: ProxyCommand /usr/sbin/prodssh --logtostderr --minloglevel=3 --dest_host=%h --dest_port=%p --dest_user=%r

STDERR (on_extended_data) comes out in STDOUT (on_data) when running with request_pty

I'm trying to run with a pty and I'm seeing that when I run with request_pty the stderr comes out in the stdout (for example if you echo into &2).

require 'net/ssh'

def exec(connection, command)
  stdout_data = ""
  stderr_data = ""

  # Create a channel
  channel = connection.open_channel do |chan|
    channel.request_pty do |cha|
      # Run the command
      cha.exec(command) do |ch, success|
        ch.on_data do |c,data|
          stdout_data += data
        end

        ch.on_extended_data do |c,type,data|
          stderr_data += data
        end
      end
    end
  end
  connection.loop

  return stdout_data, stderr_data
end


connection = Net::SSH.start('exceptionhub.com', 'root')
puts exec(connection, 'echo "something" >&2').inspect

Then expected output is ["", "something\n\r"]
Instead it outputs ["something\n\r", ""]

I'm assuming this is a bug, but I'm not really sure where to go to fix it, otherwise I would have submitted a pull request. Any help here (even just pointing me in the right direction) would be really appreciated.

Thanks

unable to convert "\xE7" from ASCII-8BIT to UTF-8 for lib/net/ssh/authentication/pageant.rb, skipping

$ gem install capistrano
Fetching: highline-1.6.11.gem (100%)
Fetching: net-ssh-2.3.0.gem (100%)
Fetching: capistrano-2.12.0.gem (100%)
Successfully installed highline-1.6.11
Successfully installed net-ssh-2.3.0
Successfully installed net-sftp-2.0.5
Successfully installed net-scp-1.0.4
Successfully installed net-ssh-gateway-1.1.0
Successfully installed capistrano-2.12.0
6 gems installed
Installing ri documentation for highline-1.6.11...
Installing ri documentation for net-ssh-2.3.0...
unable to convert "\xE7" from ASCII-8BIT to UTF-8 for lib/net/ssh/authentication/pageant.rb, skipping
Installing ri documentation for net-sftp-2.0.5...
Installing ri documentation for net-scp-1.0.4...
Installing ri documentation for net-ssh-gateway-1.1.0...
Installing ri documentation for capistrano-2.12.0...
Installing RDoc documentation for highline-1.6.11...
Installing RDoc documentation for net-ssh-2.3.0...
unable to convert "\xE7" from ASCII-8BIT to UTF-8 for lib/net/ssh/authentication/pageant.rb, skipping
Installing RDoc documentation for net-sftp-2.0.5...
Installing RDoc documentation for net-scp-1.0.4...
Installing RDoc documentation for net-ssh-gateway-1.1.0...
Installing RDoc documentation for capistrano-2.12.0...

Net::SSH.start ... ArgumentError: wrong number of arguments (2 for 3)

Example:

Net::SSH.start("asite.com", "auser", :password => "xxxxxx") do |ssh|
result = ssh.exec!("ls -l")
puts result
end

produces:

ArgumentError: wrong number of arguments (2 for 3)
from /home/christopher/work/grumples/library/factories/none.rb:25:in initialize' from /home/christopher/work/grumples/vendor/bundle/gems/net-ssh-2.6.2/lib/net/ssh/authentication/session.rb:72:innew'
from /home/christopher/work/grumples/vendor/bundle/gems/net-ssh-2.6.2/lib/net/ssh/authentication/session.rb:72:in block in authenticate' from /home/christopher/work/grumples/vendor/bundle/gems/net-ssh-2.6.2/lib/net/ssh/authentication/session.rb:65:ineach'
from /home/christopher/work/grumples/vendor/bundle/gems/net-ssh-2.6.2/lib/net/ssh/authentication/session.rb:65:in authenticate' from /home/christopher/work/grumples/vendor/bundle/gems/net-ssh-2.6.2/lib/net/ssh.rb:190:instart'
from (irb):1
from /home/christopher/work/grumples/vendor/bundle/gems/railties-3.2.9/lib/rails/commands/console.rb:47:in start' from /home/christopher/work/grumples/vendor/bundle/gems/railties-3.2.9/lib/rails/commands/console.rb:8:instart'
from /home/christopher/work/grumples/vendor/bundle/gems/railties-3.2.9/lib/rails/commands.rb:41:in <top (required)>' from script/rails:6:inrequire'
from script/rails:6:in `

'


Other info
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
Linux cb-2 3.5.0-19-generic #30-Ubuntu SMP Tue Nov 13 17:48:01 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
Rails 3.2.9

The arg error in initialize problem seems to have come back, maybe!

Any suggestions?
Ross

connect(2) (Errno::ECONNREFUSED)

Hi,
I'm not able to communicate with the remote machine using the below code. Please provide the solution

------------

My code:

-----------

!/usr/bin/ruby

require 'rubygems'
require 'net/ssh'

def SetSsh(command)

Net::SSH.start($ipdddr, "username", :password => "password") do|ssh|
result = ssh.exec!(command)
puts "result = #{result}"
end

end

Main program execution

SetSsh("ls -l")

####-End of File.

Error Which i received:

C:/Ruby187/lib/ruby/gems/1.8/gems/net-ssh-2.6.1/lib/net/ssh/transport/session.rb:67:in initialize': No connection could be made because the target machine actively refused it. - connect(2) (Errno::ECONNREFUSED) from C:/Ruby187/lib/ruby/gems/1.8/gems/net-ssh-2.6.1/lib/net/ssh/transport/session.rb:67:inopen'
from C:/Ruby187/lib/ruby/gems/1.8/gems/net-ssh-2.6.1/lib/net/ssh/transport/session.rb:67:in initialize' from C:/Ruby187/lib/ruby/1.8/timeout.rb:53:intimeout'
from C:/Ruby187/lib/ruby/1.8/timeout.rb:101:in timeout' from C:/Ruby187/lib/ruby/gems/1.8/gems/net-ssh-2.6.1/lib/net/ssh/transport/session.rb:67:ininitialize'
from C:/Ruby187/lib/ruby/gems/1.8/gems/net-ssh-2.6.1/lib/net/ssh.rb:186:in new' from C:/Ruby187/lib/ruby/gems/1.8/gems/net-ssh-2.6.1/lib/net/ssh.rb:186:instart'
from File_name.rb:49:in `SetSsh'
from File_name.rb:338

Public RSA key not identified.

The following error occurs it seems, because the public key is being improperly identified as dss.

/gems/net-ssh-2.5.2/lib/net/ssh/key_factory.rb:101:in `load_data_public_key': not a public key "/usr/joe/.ssh2/id_rsa_2048_a.pub" (OpenSSL::PKey::PKeyError)

Key looks like:
---- BEGIN SSH2 PUBLIC KEY ----
Subject: joe
Comment: "2048-bit rsa, joe@nas2000, Tue Mar 20 2012 14:17:39 -
0700"
AAAAB3NzaC1yc2EAAAADAQABAAABAQCbmWOXX0+2HUWfFdQHDiW+vMfkuetv/D+rOKtCQs
apCcxeFU9Ru5m+jZtb9ozv...
---- END SSH2 PUBLIC KEY ----

Has there been any luck getting Net::SSH working with SSH2/sshkeygen2?

Agent forwarding does not work on Windows

Agent forwarding with Pageant does't work as mentioned in #14. I tried applying the code changes suggested by @warezthebeef and @civiliz, however that doesn't do the trick for me. When trying to perform a command on another server through SSH that can only be reached by using agent forwarding it seems to hang indefinitely.

When I interrupt the command the stacktrace points to it hanging on IO#select

Does anybody have any idea as to how to make it work?

I'm trying to make this work with Ruby 1.9.3 on Windows 7.

Net::SSH known_hosts.rb, pageant.rb

submitted by: Tres Finocchiaro
from: http://redmine.ruby-lang.org/issues/show/654

Per: http://jptarqu.blogspot.com/2008/09/how-to-make-netssh-work-with-jruby-on.html

Couldn't find a mirror of these. I believe a bug report has been filed, but I couldn't find it. I wanted to provide others with a quick fix to promote development! The instructions above require modifying source, which is time consuming.

This resolves the "dl/import" error on Windows using JRuby and net/ssh.

-Tres

JRuby issue with version 2.6.0

Hi,

This commit 5917c90 which is merged in 2.6.0 causes net-ssh to break when using key authentication in JRuby (1.6.7.2, 1.7.0.preview2 in 1.8 and 1.9 mode). I spent a couple of hours trying to figure out why it was failing but was unable to.

Stack trace:

FATAL 2012-09-20 08:05:19 5900 [Vulcan::Tracking]: <ArgumentError> wrong number of arguments (2 for 1)
        /home/offers/tracking/shared/bundle/jruby/1.8/gems/net-ssh-2.6.0/lib/net/ssh/key_factory.rb:77:in `load_data_private_key'
        /home/offers/tracking/shared/bundle/jruby/1.8/gems/net-ssh-2.6.0/lib/net/ssh/key_factory.rb:42:in `load_private_key'
        /home/offers/tracking/shared/bundle/jruby/1.8/gems/net-ssh-2.6.0/lib/net/ssh/authentication/key_manager.rb:214:in `load_identities'
        org/jruby/RubyArray.java:2336:in `collect'
        /home/offers/tracking/shared/bundle/jruby/1.8/gems/net-ssh-2.6.0/lib/net/ssh/authentication/key_manager.rb:207:in `load_identities'
        /home/offers/tracking/shared/bundle/jruby/1.8/gems/net-ssh-2.6.0/lib/net/ssh/authentication/key_manager.rb:100:in `each_identity'
        /home/offers/tracking/shared/bundle/jruby/1.8/gems/net-ssh-2.6.0/lib/net/ssh/authentication/methods/publickey.rb:19:in `authenticate'
        /home/offers/tracking/shared/bundle/jruby/1.8/gems/net-ssh-2.6.0/lib/net/ssh/authentication/session.rb:78:in `authenticate'
        org/jruby/RubyArray.java:1602:in `each'
        /home/offers/tracking/shared/bundle/jruby/1.8/gems/net-ssh-2.6.0/lib/net/ssh/authentication/session.rb:65:in `authenticate'
        /home/offers/tracking/shared/bundle/jruby/1.8/gems/net-ssh-2.6.0/lib/net/ssh.rb:190:in `start'
        /home/offers/tracking/shared/bundle/jruby/1.8/gems/net-sftp-2.0.5/lib/net/sftp.rb:31:in `start'

Net::Scp raises previous command error

Hello,

I have a strange behavior with net/scp. I'm using net-ssh-2.5.2 and net-scp-1.0.4.
When a command fails, the error is "stored" and reraised on valid commands.

Here is a sample script:

require "fileutils"
require "net/scp"

# TODO
# remote_ip= 
# remote_user= 

connection= Net::SSH.start(remote_ip, remote_user, :keys_only => true)
scp= Net::SCP.new(connection)

# This raises "Errno::ENOENT: No such file or directory - /tmp/no_such_file"
begin
  scp.upload!("/tmp/no_such_file", "/tmp/test")
rescue => e
  puts "#{e.class}: #{e.message}"
end

# This also raises "Errno::ENOENT: No such file or directory - /tmp/no_such_file"!
begin
  FileUtils.touch("/tmp/scp_bug_file")
  scp.upload!("/tmp/scp_bug_file", "/tmp/test")
rescue => e
  puts "#{e.class}: #{e.message}"
end

Thomas

algorithm negotiation failed with mocana server

Hello,

I'm experiencing a failing algorithms negotiation with a mocana ssh server.

I tracked the exchanges and found out that the error is sent just after the client sent its KEY_EXCHANGE_INIT to the server. The error is a "Logged out" error code 11 (disconnected by the application server).

I connect without any problem to the server using an OpenSSH client.
I have no access to the remote equipment logs, so the error description I'm leaving is pretty poor, sorry.

Timeout::Error on Rubber deployment

I am trying to deploy a ruby on rails app with the rubber gem on amazon web services ec2. On creating a server, one of the last steps is to setup the remote aliases. In order for the gem dependencies to play nice I had to update the net-ssh gem to at least version 2.6. (I was using 2.4 and this did work). I receive the following error now in by rubber deployment...

  * 2013-02-06 20:54:58 executing `rubber:setup_remote_aliases'
    servers: ["cache01.viaresponse.com"]
connection failed for: cache01.viaresponse.com (Timeout::Error: execution expired)

Is there any idea why net-ssh is timing out when it is trying to connect to my server? I have cleared the known_hosts file and ssh agents. I also manually added my keypair to the ssh-agent. Any help would be great.

SSH::Config @@default_files does not work for user nobody

Hi,

Inside SSH::Config.load, there is an expand_path call for @@default_files. The first argument is "~/.ssh/config". However, if the user is "nobody", which is a very likely case for deployed applications in production env, the lookup errors with:

irb> ENV["HOME"] = ""
=> ""
irb> File.expand_path("~/.ssh/config")
  ArgumentError: non-absolute home
      from (irb):6:in `expand_path'
      from (irb):6

I think the gem should rescue from these errors and just skip the directory.

Thanks.

TCPKeepAlive supported?

Hello,

Is TCPKeepAlive supported? If so, is there a way I can set it?

I'm running into the issue where I am running a long-running command with no output (multiple minutes) and when the output finally is ready, I get a "closed stream" error.

See this Vagrant issue for more info: hashicorp/vagrant#516

Mitchell

Net::SSH SOCKS5 bug in ServerVersion:negotiate!

submitted by: Gerald Talton

The problem that I ran into is I saw this loop in ServerVersion:negotiate! looping forever:

loop do
  @version = socket.readline
  break if @version.nil? || @version.match(/^SSH-/)
  @header << @version
end

In the debugger, I saw the version coming back had two prepended nulls on the string and with the regular expression being /^SSH there was no way it was going to come out of that loop.

The problem was actually in socks5.rb where it was leaving the 2 nulls in the socket before handing it off for SSL negotiation. In the Socks5 negotiation, there are two exchanges (http://en.wikipedia.org/wiki/SOCKS5#SOCKS_5_protocol) and on the second exchange the interpretation of the response needed some more code, so lines

98,100:

version, reply, = socket.recv(4).unpack("C*")
len = socket.recv(1).getbyte(0)
socket.recv(len + 2)

were changed to lines 98,116:

version, reply, = socket.recv(2).unpack("C*")
socket.recv(1)
address_type = socket.recv(1).getbyte(0)
if ( address_type == 1 )
  socket.recv(4)  # get four bytes for IPv4 address
else
  if ( address_type == 3 )
    len = socket.recv(1).getbyte(0)
    hostname = socket.recv(len)
  else
    if ( address_type == 4 )
      ipv6addr hostname = socket.recv(16)
    else
      socket.close
      raise ConnectionError, "Illegal response type"
    end
  end
end
portnum = socket.recv(2)

This seemed to fix it for me so the nulls wouldn't turn up in the SSL version string loop. It also might be a good idea to put a counter in that loop that could be checked to keep the loop from going endlessly like it did, and throw some sort of exception.

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.