Created
August 3, 2022 01:39
-
-
Save nektro/fcb10ef51d567966b340ebe2901e4503 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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