github.com/rothwerx/packer@v0.9.0/builder/qemu/ssh.go (about) 1 package qemu 2 3 import ( 4 "github.com/mitchellh/multistep" 5 commonssh "github.com/mitchellh/packer/common/ssh" 6 "github.com/mitchellh/packer/communicator/ssh" 7 gossh "golang.org/x/crypto/ssh" 8 ) 9 10 func commHost(state multistep.StateBag) (string, error) { 11 return "127.0.0.1", nil 12 } 13 14 func commPort(state multistep.StateBag) (int, error) { 15 sshHostPort := state.Get("sshHostPort").(uint) 16 return int(sshHostPort), nil 17 } 18 19 func sshConfig(state multistep.StateBag) (*gossh.ClientConfig, error) { 20 config := state.Get("config").(*Config) 21 22 auth := []gossh.AuthMethod{ 23 gossh.Password(config.Comm.SSHPassword), 24 gossh.KeyboardInteractive( 25 ssh.PasswordKeyboardInteractive(config.Comm.SSHPassword)), 26 } 27 28 if config.Comm.SSHPrivateKey != "" { 29 signer, err := commonssh.FileSigner(config.Comm.SSHPrivateKey) 30 if err != nil { 31 return nil, err 32 } 33 34 auth = append(auth, gossh.PublicKeys(signer)) 35 } 36 37 return &gossh.ClientConfig{ 38 User: config.Comm.SSHUsername, 39 Auth: auth, 40 }, nil 41 }