Module: Net::SSH::Multiplex

Defined in:
lib/net/ssh/multiplex.rb,
lib/net/ssh/multiplex/client.rb,
lib/net/ssh/multiplex/control_path.rb,
lib/net/ssh/multiplex/proxy_transport.rb

Overview

Reuse of an existing OpenSSH ControlMaster connection, enabled by the :control_master option of Net::SSH.start. Net::SSH only ever connects to a master someone else started (e.g. with ssh -M or ControlMaster auto); it never becomes one.

Defined Under Namespace

Modules: PacketSocket Classes: Client, ControlPath, Error, ProxyTransport

Constant Summary collapse

DEFAULT_TIMEOUT =

Used for the mux handshake when the :timeout option isn't set.

5
MASTER_OWNED_OPTIONS =

Options for setting up a connection, which the master already did with its own settings.

%i[
  agent_socket_factory append_all_supported_algorithms auth_methods
  bind_address check_host_ip compression compression_level encryption
  fingerprint_hash global_known_hosts_file hmac host_key identity_agent
  keepalive keepalive_interval keepalive_maxcount kex key_data keycert_data
  keycerts keys keys_only known_hosts languages minimum_dh_bits no_delay
  non_interactive number_of_password_prompts passphrase password
  password_prompt prompt_without_tty proxy pubkey_algorithms
  rekey_blocks_limit rekey_limit rekey_packet_limit use_agent
  user_known_hosts_file verify_host_key
].freeze
VALUES =
[:auto, false, nil].freeze

Class Method Summary collapse

Class Method Details

.connect(host_arg, host, user, options, explicit: []) ⇒ Object

Returns a Connection::Session running through the ControlMaster for this connection, or nil (after logging why) when there is no usable master, in which case the caller connects as usual. explicit are the option names the caller passed to Net::SSH.start. Raises ArgumentError for an invalid ControlPath, as ssh does.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/net/ssh/multiplex.rb', line 46

def self.connect(host_arg, host, user, options, explicit: [])
  logger = options[:logger]
  path = socket_path(host_arg, host, user, options)
  return nil unless path

  socket = open_proxy(path, options)
  return nil unless socket

  logger.info { "control_master: using ControlMaster at #{path}" }
  log_master_owned(logger, explicit)
  begin
    transport = ProxyTransport.new(socket, host: host, control_path: path, options: options)
    Connection::Session.new(transport, session_options(logger, options))
  rescue StandardError
    socket.close
    raise
  end
end

.validate_options!(options) ⇒ Object

Raises:

  • (ArgumentError)


35
36
37
38
39
# File 'lib/net/ssh/multiplex.rb', line 35

def self.validate_options!(options)
  return if VALUES.include?(options[:control_master])

  raise ArgumentError, "control_master must be :auto or false, got #{options[:control_master].inspect}"
end