github.com/keysonzzz/kmg@v0.0.0-20151121023212-05317bfd7d39/kmgSsh/DialWithPassword.go (about) 1 package kmgSsh 2 3 import ( 4 "fmt" 5 6 "code.google.com/p/go.crypto/ssh" 7 ) 8 9 type typePassword string 10 11 func (pass typePassword) Password(user string) (password string, err error) { 12 return string(pass), nil 13 } 14 func DialWithPassword(addr string, username string, password string) (client *ssh.Client, err error) { 15 clientConfig := &ssh.ClientConfig{ 16 User: username, 17 Auth: []ssh.AuthMethod{ 18 ssh.Password(password), 19 }, 20 } 21 client, err = ssh.Dial("tcp", addr, clientConfig) 22 if err != nil { 23 return nil, fmt.Errorf("[DialWithPassword] Failed to dial: %s", err.Error()) 24 } 25 return 26 }