简体   繁体   English

GCloud ssh调用时无法连接

[英]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.

相关问题 我如何修复 ssh:tcpChan:当我通过 SSH 连接到 Redis 服务器时不支持截止日期 - how could I fix ssh: tcpChan: deadline not supported when I connect to a Redis Server over SSH Golang - 连接到 SSH 服务器 - Golang - connect to an SSH server gCloud实例:ssh:握手失败:ssh:无法验证,尝试的方法[无公钥],没有支持的方法 - gCloud instance: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain golang -- 使用用户和密码连接到 postgresql 时无法创建用户 - golang -- Cannot create user when using user & password to connect to postgresql 使用 go-chi 路由器时无法连接到 graphql playground - Cannot connect to graphql playground when using go-chi router Go 使用 docker 时无法连接到 Mongo 容器 - Go cannot connect to Mongo container when using docker Golang Cloud SDK-gcloud应用部署无法找到导入包 - Golang Cloud SDK - gcloud app deploy cannot find import package 如何让我的 GCloud Function 打开一个新的 SSH 连接以使用 SFTP 服务器? - How can I make my GCloud Function open a new SSH connection to consume a SFTP server? gcloud app部署失败“无法导入内部包” - gcloud app deploy fails “cannot import internal package” golang使用ssh连接ssh并打印错误异常 - golang connect to ssh using ssh and print error exceptions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM