Skip to content

Commit

Permalink
Make the SSH executable path configurable (#4937)
Browse files Browse the repository at this point in the history
Making this configurable is useful for windows users which may not be
using the default `ssh` executable. It also means that users can point to a
specify SSH executable if multiple are available.
  • Loading branch information
Crazybus authored and briankassouf committed Jul 18, 2018
1 parent d78934d commit 76e535e
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions command/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type SSHCommand struct {
flagNoExec bool
flagMountPoint string
flagStrictHostKeyChecking string
flagSSHExecutable string
flagUserKnownHostsFile string

// SSH CA Mode options
Expand Down Expand Up @@ -203,6 +204,15 @@ func (c *SSHCommand) Flags() *FlagSets {
"user certificate. This is specified as a comma-separated list of values.",
})

f.StringVar(&StringVar{
Name: "ssh-executable",
Target: &c.flagSSHExecutable,
Default: "ssh",
EnvVar: "VAULT_SSH_EXECUTABLE",
Completion: complete.PredictAnything,
Usage: "Path to the SSH executable to use when connecting to the host",
})

return set
}

Expand Down Expand Up @@ -473,7 +483,7 @@ func (c *SSHCommand) handleTypeCA(username, ip, port string, sshArgs []string) i
// Add extra user defined ssh arguments
args = append(args, sshArgs...)

cmd := exec.Command("ssh", args...)
cmd := exec.Command(c.flagSSHExecutable, args...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
Expand Down Expand Up @@ -522,7 +532,7 @@ func (c *SSHCommand) handleTypeOTP(username, ip, port string, sshArgs []string)
// only the Go libraries. Feel free to try and remove this dependency.
args := make([]string, 0)
env := os.Environ()
sshCmd := "ssh"
sshCmd := c.flagSSHExecutable

sshpassPath, err := exec.LookPath("sshpass")
if err != nil {
Expand All @@ -537,7 +547,7 @@ func (c *SSHCommand) handleTypeOTP(username, ip, port string, sshArgs []string)
sshCmd = sshpassPath
args = append(args,
"-e", // Read password for SSHPASS environment variable
"ssh",
c.flagSSHExecutable,
)
env = append(env, fmt.Sprintf("SSHPASS=%s", string(cred.Key)))
}
Expand Down Expand Up @@ -634,7 +644,7 @@ func (c *SSHCommand) handleTypeDynamic(username, ip, port string, sshArgs []stri
// Add extra user defined ssh arguments
args = append(args, sshArgs...)

cmd := exec.Command("ssh", args...)
cmd := exec.Command(c.flagSSHExecutable, args...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
Expand Down

0 comments on commit 76e535e

Please sign in to comment.