Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,26 @@ func runSSH(c command, host string, section *SSHConfigFileSection, agt agent.Age

// Try using each available AuthMethod to establish SSH session
var (
config *sshClientConfig
session *sshSession
err error
)
for k, m := range methods {
config := newSSHClientConfig(user, host, section, agt, m)
config, err = newSSHClientConfig(user, host, section, agt, m, options)
if err != nil {
log.Debugf("Failed to parse SSH config - %v", err)
continue
}

session, err = config.NewSession(options)
if err == nil {
break // Session established, quit trying the next AuthMethod
if err != nil {
log.Debugf("Failed to establish session with %v - %v", k, err)
continue
}

log.Debugf("Failed to establish session with %v - %v", k, err)
if session != nil {
break // Session established, quit trying the next AuthMethod
}
}

if session == nil {
Expand Down
21 changes: 17 additions & 4 deletions ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (
"os"
"os/user"
"path/filepath"
"strconv"
"syscall"
"time"

"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
Expand Down Expand Up @@ -64,16 +66,27 @@ func updateFromSSHConfigFile(section *SSHConfigFileSection, host, user *string,
}

// newSSHClientConfig initializes per-host SSH configuration.
func newSSHClientConfig(user, host string, section *SSHConfigFileSection, agt agent.Agent, method ssh.AuthMethod) *sshClientConfig {
func newSSHClientConfig(user, host string, section *SSHConfigFileSection, agt agent.Agent, method ssh.AuthMethod, options map[string]string) (*sshClientConfig, error) {
var timeout time.Duration

if ct, ok := options["ConnectTimeout"]; ok {
t, err := strconv.Atoi(ct)
if err != nil {
return nil, fmt.Errorf("ConnectTimeout is not an integer")
}
timeout = time.Second * time.Duration(t)
}

config := &ssh.ClientConfig{
User: user,
Auth: []ssh.AuthMethod{method},
User: user,
Auth: []ssh.AuthMethod{method},
Timeout: timeout,
}
return &sshClientConfig{
agent: agt,
host: host,
ClientConfig: config,
}
}, nil
}

// NewSession creates a new ssh session with the host.
Expand Down