[英]GCloud ssh cannot connect when called
I have testing code in Go, which sets up a state on a Compute Engine Instance (and don't want to expose the ports).我在 Go 中有测试代码,它在 Compute Engine 实例上设置了 state(并且不想暴露端口)。 Since there seems to be no easy way of doing this in Golang directly, I utilize
gcloud
:由于似乎没有直接在 Golang 中执行此操作的简单方法,因此我使用
gcloud
:
func TestMe(t *testing.T) {
cmd := exec.Command("gcloud", "compute", "ssh", "--project", "foo", "--tunnel-through-iap", "--zone", "europe-west1-z", "bar", `--ssh-flag="-T"`, "--", "echo WOW")
cmd.Env = os.Environ()
out, err := cmd.CombinedOutput()
println(string(out))
t.Fatal(err)
}
When running go test
, cmd
outputs:运行
go test
时, cmd
输出:
bash: myuser@compute.123456789: command not found
The compute instance is correct - but something fails when trying to access the compute instance.计算实例是正确的 - 但尝试访问计算实例时出现故障。 The same gcloud command works in bash (even for non-interactive).
相同的 gcloud 命令适用于 bash(即使对于非交互式)。 I assume there is something different in the Golang environment.
我认为 Golang 环境中有些不同。
There is a small correction in the code.代码中有一个小的更正。
corrected code:更正的代码:
func TestMe(t *testing.T)
{
cmd := exec.Command("gcloud", "compute", "ssh", "--project", "foo", "--tunnel-through-iap", "--zone", "europe-west1-z", "bar", "--ssh-flag=-T", "--", "echo WOW")
cmd.Env = os.Environ()
out, err := cmd.CombinedOutput()
println(string(out))
t.Fatal(err)
}
For more information related to troubleshooting ssh issues you can refer to the documentation .有关解决 ssh 问题的更多信息,您可以参考文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.