Skip to content

Instantly share code, notes, and snippets.

@nektro
Created August 3, 2022 01:39
Embed
What would you like to do?
package main
import (
"bytes"
"fmt"
"golang.org/x/crypto/ssh"
)
func main() {
config := ssh.ClientConfig{
User: "root",
Auth: []ssh.AuthMethod{
ssh.Password("root"),
},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}
client, _ := ssh.Dial("tcp", "localhost:2222", &config)
defer client.Close()
sess, _ := client.NewSession()
defer sess.Close()
var buff bytes.Buffer
sess.Stdout = &buff
sess.Run("uname -a")
fmt.Print(buff.String())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment