Use PasswordCallback instead of Password for ssh

Currently asking for login password, even if not supported by
the ssh server. So wait with prompt until actually requested.

Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
This commit is contained in:
Anders F Björklund 2020-12-04 17:08:39 +01:00
parent 70284b18cc
commit aaade40780
1 changed files with 4 additions and 4 deletions

View File

@ -207,11 +207,11 @@ func sshClient(_url *url.URL, secure bool, passPhrase string, identity string) (
authMethods = append(authMethods, ssh.Password(pw))
}
if len(authMethods) == 0 {
pass, err := terminal.ReadPassword("Login password:")
if err != nil {
return Connection{}, err
callback := func() (string, error) {
pass, err := terminal.ReadPassword("Login password:")
return string(pass), err
}
authMethods = append(authMethods, ssh.Password(string(pass)))
authMethods = append(authMethods, ssh.PasswordCallback(callback))
}
port := _url.Port()