github.com/StackPointCloud/packer@v0.10.2-0.20180716202532-b28098e0f79b/builder/virtualbox/common/ssh.go (about) 1 package common 2 3 import ( 4 commonssh "github.com/hashicorp/packer/common/ssh" 5 "github.com/hashicorp/packer/communicator/ssh" 6 "github.com/hashicorp/packer/helper/multistep" 7 gossh "golang.org/x/crypto/ssh" 8 ) 9 10 func CommHost(host string) func(multistep.StateBag) (string, error) { 11 return func(state multistep.StateBag) (string, error) { 12 return host, nil 13 } 14 } 15 16 func SSHPort(state multistep.StateBag) (int, error) { 17 sshHostPort := state.Get("sshHostPort").(int) 18 return sshHostPort, nil 19 } 20 21 func SSHConfigFunc(config SSHConfig) func(multistep.StateBag) (*gossh.ClientConfig, error) { 22 return func(state multistep.StateBag) (*gossh.ClientConfig, error) { 23 auth := []gossh.AuthMethod{ 24 gossh.Password(config.Comm.SSHPassword), 25 gossh.KeyboardInteractive( 26 ssh.PasswordKeyboardInteractive(config.Comm.SSHPassword)), 27 } 28 29 if config.Comm.SSHPrivateKey != "" { 30 signer, err := commonssh.FileSigner(config.Comm.SSHPrivateKey) 31 if err != nil { 32 return nil, err 33 } 34 35 auth = append(auth, gossh.PublicKeys(signer)) 36 } 37 38 return &gossh.ClientConfig{ 39 User: config.Comm.SSHUsername, 40 Auth: auth, 41 HostKeyCallback: gossh.InsecureIgnoreHostKey(), 42 }, nil 43 } 44 }