微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法使用 gcloud SSH 进入计算引擎实例

如何解决无法使用 gcloud SSH 进入计算引擎实例

我已经在 Mac 上安装了 GCP 的云 SDK,我拥有所有者的角色,我正在尝试使用此命令通过 ssh 连接到计算引擎实例之一。

gcloud compute ssh user@instance-name

很遗憾,我遇到了错误。这是我执行该命令的输出

External IP address was not found; defaulting to using IAP tunneling.
ERROR: (gcloud.compute.start-iap-tunnel) Error while connecting [[Errno 1] Operation not permitted].
kex_exchange_identification: Connection closed by remote host
ERROR: (gcloud.compute.ssh) [/usr/bin/ssh] exited with return code [255].

奇怪的是,我能够使用 cloud shell ssh 进入实例。所以我认为 IAP 隧道设置正确。我的一位同事也可以使用他的 mac 上的 cloud sdk 进行 ssh。

我相信我的云 sdk 设置可能有问题,但我不确定。

编辑:我尝试以冗长的方式执行命令:

gcloud compute ssh --verbosity=debug instance-name

查看输出,我认为我的网络套接字可能有问题。也许我的笔记本电脑的防火墙设置禁止它。虽然我不确定:

gcloud compute ssh --verbosity=debug instance-name
DEBUG: Running [gcloud.compute.ssh] with arguments: [--verbosity: "debug",[USER@]INSTANCE: "instance-name"]
DEBUG: Starting new HTTPS connection (1): compute.googleapis.com:443
DEBUG: https://compute.googleapis.com:443 "POST /batch/compute/v1 HTTP/1.1" 200 None
DEBUG: https://compute.googleapis.com:443 "POST /batch/compute/v1 HTTP/1.1" 200 None
External IP address was not found; defaulting to using IAP tunneling.
DEBUG: Starting new HTTPS connection (1): oslogin.googleapis.com:443
DEBUG: https://oslogin.googleapis.com:443 "GET /v1/users/myid@some-org.com/loginProfile?alt=json&projectId=myproject-id HTTP/1.1" 200 None
INFO: Using OS Login user [myid_someorg_com] instead of default user [sahil]
DEBUG: SSH KNown Hosts File [/Users/sahil/.ssh/google_compute_kNown_hosts] Could not be opened: Unable to read file [/Users/sahil/.ssh/google_compute_kNown_hosts]: [Errno 2] No such file or directory: '/Users/sahil/.ssh/google_compute_kNown_hosts'
DEBUG: Running command [/usr/bin/ssh -t -i /Users/sahil/.ssh/google_compute_engine -o CheckHostIP=no -o HostKeyAlias=compute.5622012345678901234 -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKNownHostsFile=/Users/sahil/.ssh/google_compute_kNown_hosts -o ProxyCommand /Users/sahil/gcloud/google-cloud-sdk/platform/bundledpythonunix/bin/python3 /Users/sahil/gcloud/google-cloud-sdk/lib/gcloud.py compute start-iap-tunnel instance-name %p --listen-on-stdin --project=myproject-id --zone=us-central1-a --verbosity=debug -o ProxyUseFdpass=no myid_someorg_com@compute.5622012345678901234].
DEBUG: Executing command: ['/usr/bin/ssh','-t','-i','/Users/sahil/.ssh/google_compute_engine','-o','CheckHostIP=no','HostKeyAlias=compute.5622012345678901234','IdentitiesOnly=yes','StrictHostKeyChecking=no','UserKNownHostsFile=/Users/sahil/.ssh/google_compute_kNown_hosts','ProxyCommand /Users/sahil/gcloud/google-cloud-sdk/platform/bundledpythonunix/bin/python3 /Users/sahil/gcloud/google-cloud-sdk/lib/gcloud.py compute start-iap-tunnel instance-name %p --listen-on-stdin --project=myproject-id --zone=us-central1-a --verbosity=debug','ProxyUseFdpass=no','myid_someorg_com@compute.5622012345678901234']
DEBUG: Loaded Command Group: ['gcloud']
DEBUG: Loaded Command Group: ['gcloud','beta']
DEBUG: Loaded Command Group: ['gcloud','compute']
DEBUG: Loaded Command Group: ['gcloud','compute','start_iap_tunnel']
DEBUG: Running [gcloud.compute.start-iap-tunnel] with arguments: [--listen-on-stdin: "True",--project: "myproject-id",--verbosity: "debug",--zone: "us-central1-a",INSTANCE_NAME: "instance-name",INSTANCE_PORT: "22"]
DEBUG: Starting new HTTPS connection (1): compute.googleapis.com:443
DEBUG: https://compute.googleapis.com:443 "POST /batch/compute/v1 HTTP/1.1" 200 None
DEBUG: credentials type for _GetAccesstokenCallback is [<googlecloudsdk.core.credentials.google_auth_credentials.UserCredWithReauth object at 0x1104a3f10>].
DEBUG: Making request: POST https://oauth2.googleapis.com/token
DEBUG: Starting new HTTPS connection (1): oauth2.googleapis.com:443
DEBUG: https://oauth2.googleapis.com:443 "POST /token HTTP/1.1" 200 None
INFO: Connecting with URL ['wss://tunnel.cloudproxy.app/v4/connect?project=myproject-id&zone=us-central1-a&instance=instance-name&interface=nic0&port=22']
DEBUG: Error during WebSocket processing.
Traceback (most recent call last):
  File "/Users/sahil/gcloud/google-cloud-sdk/lib/third_party/websocket/_app.py",line 254,in run_forever
    proxy_type=proxy_type)
  File "/Users/sahil/gcloud/google-cloud-sdk/lib/third_party/websocket/_core.py",line 223,in connect
    options.pop('socket',None))
  File "/Users/sahil/gcloud/google-cloud-sdk/lib/third_party/websocket/_http.py",line 120,in connect
    sock = _open_socket(addrinfo_list,options.sockopt,options.timeout)
  File "/Users/sahil/gcloud/google-cloud-sdk/lib/third_party/websocket/_http.py",line 189,in _open_socket
    raise error
  File "/Users/sahil/gcloud/google-cloud-sdk/lib/third_party/websocket/_http.py",line 172,in _open_socket
    sock.connect(address)
PermissionError: [Errno 1] Operation not permitted
INFO: Error during WebSocket processing:
PermissionError: [Errno 1] Operation not permitted

INFO: Client closed connection from [stdin].
DEBUG: (gcloud.compute.start-iap-tunnel) Error while connecting [[Errno 1] Operation not permitted].
Traceback (most recent call last):
  File "/Users/sahil/gcloud/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py",line 982,in Execute
    resources = calliope_command.Run(cli=self,args=args)
  File "/Users/sahil/gcloud/google-cloud-sdk/lib/googlecloudsdk/calliope/backend.py",line 809,in Run
    resources = command_instance.Run(args)
  File "/Users/sahil/gcloud/google-cloud-sdk/lib/surface/compute/start_iap_tunnel.py",line 129,in Run
    iap_tunnel_helper.Run()
  File "/Users/sahil/gcloud/google-cloud-sdk/lib/googlecloudsdk/command_lib/compute/iap_tunnel.py",line 633,in Run
    self._RunReceiveLocalData(_StdinSocket(),'stdin')
  File "/Users/sahil/gcloud/google-cloud-sdk/lib/googlecloudsdk/command_lib/compute/iap_tunnel.py",line 498,in _RunReceiveLocalData
    store.LoadIfEnabled(use_google_auth=True)))
  File "/Users/sahil/gcloud/google-cloud-sdk/lib/googlecloudsdk/command_lib/compute/iap_tunnel.py",line 466,in _InitiateWebSocketConnection
    new_websocket.InitiateConnection()
  File "/Users/sahil/gcloud/google-cloud-sdk/lib/googlecloudsdk/api_lib/compute/iap_tunnel_websocket.py",line 132,in InitiateConnection
    self._WaitForOpenorraiseerror()
  File "/Users/sahil/gcloud/google-cloud-sdk/lib/googlecloudsdk/api_lib/compute/iap_tunnel_websocket.py",line 350,in _WaitForOpenorraiseerror
    raise ConnectionCreationError(error_msg)
googlecloudsdk.api_lib.compute.iap_tunnel_websocket.ConnectionCreationError: Error while connecting [[Errno 1] Operation not permitted].
ERROR: (gcloud.compute.start-iap-tunnel) Error while connecting [[Errno 1] Operation not permitted].
kex_exchange_identification: Connection closed by remote host
DEBUG: (gcloud.compute.ssh) [/usr/bin/ssh] exited with return code [255].
Traceback (most recent call last):
  File "/Users/sahil/gcloud/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py",in Run
    resources = command_instance.Run(args)
  File "/Users/sahil/gcloud/google-cloud-sdk/lib/surface/compute/ssh.py",line 306,in Run
    force_connect=properties.VALUES.ssh.putty_force_connect.GetBool())
  File "/Users/sahil/gcloud/google-cloud-sdk/lib/googlecloudsdk/command_lib/util/ssh/ssh.py",line 1313,in Run
    raise CommandError(args[0],return_code=status)
googlecloudsdk.command_lib.util.ssh.ssh.CommandError: [/usr/bin/ssh] exited with return code [255].
ERROR: (gcloud.compute.ssh) [/usr/bin/ssh] exited with return code [255].

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。