Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: SSH interactive passwords #126

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (c *SSHClient) parseHost(host string) error {
}

var initAuthMethodOnce sync.Once
var authMethod ssh.AuthMethod
var signers []ssh.Signer

// initAuthMethod initiates SSH authentication method.
func initAuthMethod() {
Expand Down Expand Up @@ -105,9 +105,7 @@ func initAuthMethod() {
continue
}
signers = append(signers, signer)

}
authMethod = ssh.PublicKeys(signers...)
}

// SSHDialFunc can dial an ssh server and return a client
Expand Down Expand Up @@ -137,7 +135,19 @@ func (c *SSHClient) ConnectWith(host string, dialer SSHDialFunc) error {
config := &ssh.ClientConfig{
User: c.user,
Auth: []ssh.AuthMethod{
authMethod,
ssh.PublicKeysCallback(func() ([]ssh.Signer, error) {
return signers, nil
}),
ssh.KeyboardInteractive(func(user string, instruction string, questions []string, echos []bool) (answers []string, err error) {
answers = make([]string, len(questions))
panic(fmt.Sprintf("%+v", questions))
for n, q := range questions {
_ = q
answers[n] = ""
}

return answers, nil
}),
},
}

Expand Down