From 26432b771fa888facefe3772b2473bb54d9f4da4 Mon Sep 17 00:00:00 2001 From: Evan Hazlett Date: Fri, 1 May 2015 12:41:19 -0400 Subject: [PATCH] ssh: allocate pty for sudo over ssh for those that have requiretty Signed-off-by: Evan Hazlett --- ssh/client.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) 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 {