mirror of https://github.com/docker/docs.git
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:
parent
91c618fd06
commit
26432b771f
|
@ -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)
|
||||
|
||||
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 {
|
||||
|
|
Loading…
Reference in New Issue