diff --git a/ssh/client.go b/ssh/client.go index a102fa5ca6..ad6c2c3e50 100644 --- a/ssh/client.go +++ b/ssh/client.go @@ -10,6 +10,7 @@ import ( "github.com/docker/machine/log" "github.com/docker/machine/utils" "golang.org/x/crypto/ssh" + "golang.org/x/crypto/ssh/terminal" ) type Client interface { @@ -156,7 +157,29 @@ func (client NativeClient) Output(command string) (string, error) { output, err := session.CombinedOutput(command) - return string(output), err + fd := int(os.Stdin.Fd()) + if err != nil { + return string(output), err + } + + termWidth, termHeight, err := terminal.GetSize(fd) + if err != nil { + return string(output), err + } + + modes := ssh.TerminalModes{ + ssh.ECHO: 1, + ssh.TTY_OP_ISPEED: 14400, + ssh.TTY_OP_OSPEED: 14400, + } + + // request tty -- fixes error with hosts that use + // "Defaults requiretty" in /etc/sudoers - I'm looking at you RedHat + if err := session.RequestPty("xterm-256color", termHeight, termWidth, modes); err != nil { + return string(output), err + } + + return string(output), session.Run(command) } func (client NativeClient) Shell() error {