Skip to content

Instantly share code, notes, and snippets.

@nektro
Created August 3, 2022 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nektro/fcb10ef51d567966b340ebe2901e4503 to your computer and use it in GitHub Desktop.
Save nektro/fcb10ef51d567966b340ebe2901e4503 to your computer and use it in GitHub Desktop.
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