1. Computing

Net::SSH Classes--Interfacing With the Net::SSH Library

Secure Shell Networking

By

Net::SSH::Connection::Session

A Net::SSH::Connection::Session object represents an authenticated session ready to create channels, forward ports, transfer files, etc. The Session object is the reference point for all actions performed on that SSH connection and runs the event loop.

The Net::SSH::Connection::Session object is always created using the Net::SSH::start method, never constructed manually. This is the primary interface through which you will interact with the Net::SSH library.

Net::SSH::Connection::Channel

The Channel is an important concept in SSH. Though you only have one connection to the remote SSH host, many Channels are multiplexed through this connection. This allows you to, for example, forward a port through the connection, and, at the same time run a program or run two programs simultaneously. Each action happens in its own channel, and is multiplexed through the same connection.

The Net::SSH library contains handy abstractions for most common tasks so you don't always have to think about channels. However, to get the most out of the library, you'll have to learn about channels.

Channels are used by requesting a new channel from the Session object. From there, you can either execute a program or start an SSH subsystem (like SFTP) and register a number of callbacks. These callbacks are run on certain events, such as data being received, an end of file, or the channel closing. You can wrap your channels in callbacks to make state machines to perform required tasks.

Net::SSH::Service::Forward

A common thing to do with SSH is to forward network connections. This is done to tunnel traffic through hostile networks using the SSH encrypted connection. SSH port forwards are extremely useful.

The Forward class represents a port forward active on a session. When a Forward is created, it will allocate a new channel and instruct SSH to forward network traffic to or from the remote SSH host. The Forward class is almost never instantiated manually, but created using the Net::SSH::Connection::Session::forward helper method.

See More About
  1. About.com
  2. Computing
  3. Ruby
  4. Networking
  5. SSH
  6. Net::SSH Classes--Interfacing With the Net::SSH Library

©2014 About.com. All rights reserved.