Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "golang.org/x/crypto/ssh"
- )
- func main() {
- username := "user"
- password := "pass"
- server := "server:22"
- config := &ssh.ClientConfig{
- User: username,
- Auth: []ssh.AuthMethod{
- ssh.Password(password),
- },
- HostKeyCallback: ssh.InsecureIgnoreHostKey(),
- }
- client, _ := ssh.Dial("tcp", server, config)
- defer client.Close()
- runCommand := func(cmd string) {
- session, _ := client.NewSession()
- defer session.Close()
- output, _ := session.Output(cmd)
- fmt.Printf("Output: %s", output)
- }
- runCommand(`date +"%T.%N"`)
- runCommand(`date +"%T.%N"`)
- }
Advertisement
Add Comment
Please, Sign In to add comment