diff --git a/builder/scaleway/ssh.go b/builder/scaleway/ssh.go index 017138022..d1ac5dfc8 100644 --- a/builder/scaleway/ssh.go +++ b/builder/scaleway/ssh.go @@ -2,9 +2,10 @@ package scaleway import ( "fmt" - "golang.org/x/crypto/ssh" + packerssh "github.com/hashicorp/packer/communicator/ssh" "github.com/mitchellh/multistep" + "golang.org/x/crypto/ssh" ) func commHost(state multistep.StateBag) (string, error) { @@ -14,17 +15,32 @@ func commHost(state multistep.StateBag) (string, error) { func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) { config := state.Get("config").(Config) - privateKey := state.Get("privateKey").(string) + var privateKey string + + var auth []ssh.AuthMethod + + if config.Comm.SSHPassword != "" { + auth = []ssh.AuthMethod{ + ssh.Password(config.Comm.SSHPassword), + ssh.KeyboardInteractive( + packerssh.PasswordKeyboardInteractive(config.Comm.SSHPassword)), + } + } - signer, err := ssh.ParsePrivateKey([]byte(privateKey)) - if err != nil { - return nil, fmt.Errorf("Error setting up SSH config: %s", err) + if config.Comm.SSHPrivateKey != "" { + if priv, ok := state.GetOk("privateKey"); ok { + privateKey = priv.(string) + } + signer, err := ssh.ParsePrivateKey([]byte(privateKey)) + if err != nil { + return nil, fmt.Errorf("Error setting up SSH config: %s", err) + } + auth = append(auth, ssh.PublicKeys(signer)) } return &ssh.ClientConfig{ - User: config.Comm.SSHUsername, - Auth: []ssh.AuthMethod{ - ssh.PublicKeys(signer), - }, + User: config.Comm.SSHUsername, + Auth: auth, + HostKeyCallback: ssh.InsecureIgnoreHostKey(), }, nil }