Class: ZTK::SSH

Inherits:
Base
  • Object
show all
Includes:
Bootstrap, Command, Console, Core, Download, Exec, File, Private, Upload
Defined in:
lib/ztk/ssh.rb,
lib/ztk/ssh/file.rb,
lib/ztk/ssh/core.rb,
lib/ztk/ssh/exec.rb,
lib/ztk/ssh/upload.rb,
lib/ztk/ssh/console.rb,
lib/ztk/ssh/private.rb,
lib/ztk/ssh/command.rb,
lib/ztk/ssh/download.rb,
lib/ztk/ssh/bootstrap.rb

Overview

SSH Multi-function Class

We can get a new instance of SSH like so:

ssh = ZTK::SSH.new

If we wanted to redirect STDOUT and STDERR to a StringIO we can do this:

std_combo = StringIO.new
ui = ZTK::UI.new(:stdout => std_combo, :stderr => std_combo)
ssh = ZTK::SSH.new(:ui => ui)

If you want to specify SSH options you can:

keys = File.expand_path(File.join(ENV['HOME'], '.ssh', 'id_rsa'))
ssh = ZTK::SSH.new(:host_name => '127.0.0.1', :user => ENV['USER'], :keys => keys)

= Configuration Examples:

To proxy through another host, for example SSH to 192.168.1.1 through 192.168.0.1:

ssh.config do |config|
  config.user = ENV['USER']
  config.host_name = '192.168.1.1'
  config.proxy_user = ENV['USER']
  config.proxy_host_name = '192.168.0.1'
end

Specify an identity file:

ssh.config do |config|
  config.keys = File.expand_path(File.join(ENV['HOME'], '.ssh', 'id_rsa'))
  config.proxy_keys = File.expand_path(File.join(ENV['HOME'], '.ssh', 'id_rsa'))
end

Specify a timeout:

ssh.config do |config|
  config.timeout = 30
end

Specify a password:

ssh.config do |config|
  config.password = 'p@$$w0rd'
end

Check host keys, the default is false (off):

ssh.config do |config|
  config.host_key_verify = true
end

Author:

Defined Under Namespace

Modules: Bootstrap, Command, Console, Core, Download, Exec, File, Private, Upload

Constant Summary

EXIT_SIGNALS =

Exit Signal Mappings

{
  1 => "SIGHUP",
  2 => "SIGINT",
  3 => "SIGQUIT",
  4 => "SIGILL",
  5 => "SIGTRAP",
  6 => "SIGABRT",
  7 => "SIGBUS",
  8 => "SIGFPE",
  9 => "SIGKILL",
  10 => "SIGUSR1",
  11 => "SIGSEGV",
  12 => "SIGUSR2",
  13 => "SIGPIPE",
  14 => "SIGALRM",
  15 => "SIGTERM",
  # 16 unused?
  17 => "SIGCHLD",
  18 => "SIGCONT",
  19 => "SIGSTOP",
  20 => "SIGTSTP",
  21 => "SIGTTIN",
  22 => "SIGTTOU",
  23 => "SIGURG",
  24 => "SIGXCPU",
  25 => "SIGXFSZ",
  26 => "SIGVTALRM",
  27 => "SIGPROF"
}
RESCUE_RETRY_ATTEMPTS =
5

Instance Method Summary (collapse)

Methods included from Private

#base_options, #gateway_options, #log_header, #process_key, #process_keys, #ssh_options, #tag

Methods included from Upload

#upload

Methods included from File

#file

Methods included from Exec

#exec

Methods included from Download

#download

Methods included from Core

#close, #close_gateway, #close_ssh, #do_proxy?, #gateway, #on_retry, #scp, #sftp, #ssh

Methods included from Console

#console

Methods included from Command

#console_command, #proxy_command

Methods included from Bootstrap

#bootstrap

Methods inherited from Base

build_config, #config, #direct_log, hash_config, log_and_raise, #log_and_raise

Constructor Details

- (SSH) initialize(configuration = {})

Returns a new instance of SSH

Parameters:

  • configuration (Hash) (defaults to: {})

    Configuration options hash.

  • options (Hash)

    a customizable set of options

Options Hash (configuration):

  • :host_name (String)

    Server hostname to connect to.

  • :user (String)

    Username to use for authentication.

  • :keys (String, Array<String>)

    A single or series of identity files to use for authentication. You can also supply keys as String blobs which will be rendered to temporary files automatically.

  • :password (String)

    Password to use for authentication.

  • :timeout (Integer) — default: 60

    SSH connection timeout in seconds to use.

  • :compression (Boolean) — default: false

    Whether or not to use compression for this session.

  • :compression_level (Integer)

    What level of compression to use.

  • :proxy_host_name (String)

    Server hostname to proxy through.

  • :proxy_user (String)

    Username to use for proxy authentication.

  • :request_pty (Boolean) — default: true

    Whether or not we should try to obtain a PTY

  • :ignore_exit_status (Boolean) — default: false

    Whether or not we should throw an exception if the exit status is not kosher.

  • :forward_agent (Boolean) — default: true

    Whether or not to enable SSH agent forwarding.

  • :proxy_keys (String, Array<String>)

    A single or series of identity files to use for authentication with the proxy.



158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/ztk/ssh.rb', line 158

def initialize(configuration={})
  super({
    :forward_agent => true,
    :compression => false,
    :user_known_hosts_file => '/dev/null',
    :timeout => 60,
    :ignore_exit_status => false,
    :request_pty => true,
    :exit_code => 0,
    :silence => false
  }, configuration)
end