Golang ssh

From UVOO Tech Wiki
Revision as of 21:39, 8 December 2020 by Busk (talk | contribs) (Created page with "https://stackoverflow.com/questions/37679939/how-do-i-execute-a-command-on-a-remote-machine-in-a-golang-cli ``` package main import ( "bytes" "log" "os/exec" )...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

https://stackoverflow.com/questions/37679939/how-do-i-execute-a-command-on-a-remote-machine-in-a-golang-cli

package main

import (
    "bytes"
    "log"
    "os/exec"
)

func main() {
    cmd := exec.Command("ssh", "remote-machine", "bash-command")
    var out bytes.Buffer
    cmd.Stdout = &out
    err := cmd.Run()
    if err != nil {
        log.Fatal(err)
    }
}
To jump over machines use the ProxyCommand directive in a ssh config file.

Host remote_machine_name
  ProxyCommand ssh -q bastion nc remote_machine_ip 22