Authenticating with a password

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())) ...

Get Security with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.