You want to securely send data or commands back and forth between your computer, and another computer on which you have a shell account.
Net::SSH module, which implements the SSH2
protocol. It's found in the
gem, although some operating systems package it themselves. It lets you implement Ruby applications that work like
You can start an SSH session by passing a hostname to
Net::SSH::start, along with your shell
username and password on that host. If you have an SSH public/private
key pair set up between your computer and the remote host, you can
omit the username and password:
require 'rubygems' require 'net/ssh' Net::SSH.start('example.com', :username=>'leonardr', :password=>'mypass') do |session| # Manipulate your Net::SSH::Session object here… end
Net::SSH::start takes a code
block, to which it passes a
Net::SSH::Session object. You use the
session object to send encrypted data between the machines, or to
spawn processes on the remote machine. When the code block ends, the
SSH session is automatically terminated.
It seems strange now, but until the late 1990s, people routinely used unsecured protocols like telnet to get shell access to remote machines. Remote access was so useful that we were willing to jeopardize our electronic safety by sending our shell passwords (not to mention all the data we looked at) unencrypted across the network. Fortunately, we don't have to make that trade-off ...