Class: Capistrano::SSH
- Inherits:
-
Object
- Object
- Capistrano::SSH
- Defined in:
- lib/capistrano/ssh.rb
Overview
A helper class for dealing with SSH connections.
Defined Under Namespace
Modules: Server
Constant Summary collapse
- DEFAULT_PORT =
The default port for SSH.
22
Class Method Summary collapse
-
.connect(server, options = {}, &block) ⇒ Object
An abstraction to make it possible to connect to the server via public key without prompting for the password.
Class Method Details
.connect(server, options = {}, &block) ⇒ Object
An abstraction to make it possible to connect to the server via public key without prompting for the password. If the public key authentication fails this will fall back to password authentication.
server
must be an instance of ServerDefinition.
If a block is given, the new session is yielded to it, otherwise the new session is returned.
If an :ssh_options key exists in options
, it is passed to the Net::SSH constructor. Values in options
are then merged into it, and any connection information in server
is added last, so that server
info takes precedence over options
, which takes precendence over ssh_options.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/capistrano/ssh.rb', line 85 def self.connect(server, ={}, &block) methods = [ %w(publickey hostbased), %w(password keyboard-interactive) ] password_value = nil = ([:ssh_options] || {}).dup [:username] = server.user || [:user] || [:username] [:port] = server.port || [:port] || [:port] || DEFAULT_PORT begin = .merge( :password => password_value, :auth_methods => [:auth_methods] || methods.shift ) connection = Net::SSH.start(server.host, , &block) Server.apply_to(connection, server) rescue Net::SSH::AuthenticationFailed raise if methods.empty? || [:auth_methods] password_value = [:password] retry end end |