ssh: allocate pty for sudo over ssh for those that have requiretty

Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
Evan Hazlett 2015-05-01 12:41:19 -04:00
parent 91c618fd06
commit 26432b771f
1 changed files with 24 additions and 1 deletions

View File

@ -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 {