Guest User

Go (golang.org/x/crypto/ssh)

a guest
Sep 20th, 2024
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "golang.org/x/crypto/ssh"
  6. )
  7.  
  8. func main() {
  9. username := "user"
  10. password := "pass"
  11. server := "server:22"
  12. config := &ssh.ClientConfig{
  13. User: username,
  14. Auth: []ssh.AuthMethod{
  15. ssh.Password(password),
  16. },
  17. HostKeyCallback: ssh.InsecureIgnoreHostKey(),
  18. }
  19.  
  20. client, _ := ssh.Dial("tcp", server, config)
  21. defer client.Close()
  22.  
  23. runCommand := func(cmd string) {
  24. session, _ := client.NewSession()
  25. defer session.Close()
  26. output, _ := session.Output(cmd)
  27. fmt.Printf("Output: %s", output)
  28. }
  29.  
  30. runCommand(`date +"%T.%N"`)
  31. runCommand(`date +"%T.%N"`)
  32. }
Advertisement
Add Comment
Please, Sign In to add comment