Password authentication over SSH is the simplest method. This example demonstrates how to configure an SSH client with the ssh.ClientConfig struct and then connect to an SSH server using ssh.Dial(). The client is configured to use a password by specifying ssh.Password() as the authentication function:
package mainimport ( "golang.org/x/crypto/ssh" "log")var username = "username"var password = "password"var host = "example.com:22"func main() { config := &ssh.ClientConfig{ User: username, Auth: []ssh.AuthMethod{ ssh.Password(password), }, HostKeyCallback: ssh.InsecureIgnoreHostKey(), } client, err := ssh.Dial("tcp", host, config) if err != nil { log.Fatal("Error dialing server. ", err) } log.Println(string(client.ClientVersion())) ...