由于上面的评论,我可以使用密码使用ssh访问。我使用了golang的ssh api库。当我遵循以下示例时,这非常简单:
https://pre.google.com/p/go/source/browse/ssh/example_test.go?repo=crypto
特别:
func ExampleDial() { // An SSH client is represented with a ClientConn. Currently only // the "password" authentication method is supported. // // To authenticate with the remote server you must pass at least one // implementation of AuthMethod via the Auth field in ClientConfig. config := &ClientConfig{ User: "username", Auth: []AuthMethod{ Password("yourpassword"), }, } client, err := Dial("tcp", "yourserver.com:22", config) if err != nil { panic("Failed to dial: " + err.Error()) } // Each ClientConn can support multiple interactive sessions, // represented by a Session. session, err := client.NewSession() if err != nil { panic("Failed to create session: " + err.Error()) } defer session.Close() // once a Session is created, you can execute a single command on // the remote side using the Run method. var b bytes.Buffer session.Stdout = &b if err := session.Run("/usr/bin/whoami"); err != nil { panic("Failed to run: " + err.Error()) } fmt.Println(b.String())}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)