I'm trying to ssh in to a group of servers that don't support a regular shell. The /crypto/ssh library doesn't work for these hence I'm using a direct ssh through exec.Command
.
Now the problem is that this command just hangs if I pass -o StrictHostKeyChecking=no
, i.e: exec.Command("ssh", "-o", "StrictHostKeyChecking=no", config.User + "@" + host)
but works for a simple
exec.Command("ssh", "-T", config.User + "@" + host)
The full block of code is here (it basically just needs to pipe a command to an ssh connection like so
echo hostname | ssh -T -o StrictHostKeyChecking=no user1@db1-ar6.name.local
:
p1 := exec.Command("echo", config.Command)
p2 := exec.Command("ssh", "-o", "StrictHostKeyChecking=no", config.User + "@" + host)
//p2 := exec.Command("ssh", "-T", config.User + "@" + host) //doesn't work
fmt.Println(p2) //checking output
var stdout, stderr bytes.Buffer
p2.Stdout = &stdout
p2.Stderr = &stderr
p2.Stdin, _ = p1.StdoutPipe() // p1 pipe to p2 ssh
err1 := p2.Start() // start ssh command but dont wait for it to finish
if err1 != nil {
return errors.Wrap(err1, "starting ssh session failed")
}
err2 := p1.Run() // run pipe command and wait for it to finish
if err2 != nil {
return errors.Wrap(err2, config.Command+" failed", )
}
err3 := p2.Wait() // ssh wait for pipe to close
if err3 != nil {
return errors.Wrap(err3, "ssh wait failed")
}
Output is, and the wait function fails:
&{/usr/bin/ssh [ssh -o StrictHostKeyChecking=no user1@db1-ar6.name.local] [] <nil> <nil> <nil> [] <nil> <nil> <nil> <nil> <nil> false [] [] [] [] <nil> <nil>}
2019/05/24 10:28:41 ssh wait failed: exit status 255