From 0c6249df7f1359d6bf3f2770bea7845947cd6db0 Mon Sep 17 00:00:00 2001 From: r_takaishi Date: Mon, 9 Mar 2020 11:54:53 +0900 Subject: [PATCH] use tty when IsTerminal is false --- communicator/ssh/keyboard_interactive.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/communicator/ssh/keyboard_interactive.go b/communicator/ssh/keyboard_interactive.go index 33dd68463..66e7fef6d 100644 --- a/communicator/ssh/keyboard_interactive.go +++ b/communicator/ssh/keyboard_interactive.go @@ -1,11 +1,10 @@ package ssh import ( - "log" - "os" - "golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh/terminal" + "log" + "os" ) func KeyboardInteractive() ssh.KeyboardInteractiveChallenge { @@ -21,7 +20,18 @@ func KeyboardInteractive() ssh.KeyboardInteractiveChallenge { } answers := make([]string, len(questions)) for i := range questions { - s, err := terminal.ReadPassword(int(os.Stdin.Fd())) + var fd int + if terminal.IsTerminal(int(os.Stdin.Fd())) { + fd = int(os.Stdin.Fd()) + } else { + tty, err := os.Open("/dev/tty") + if err != nil { + return nil, err + } + defer tty.Close() + fd = int(tty.Fd()) + } + s, err := terminal.ReadPassword(fd) if err != nil { return nil, err }