You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows下VS Code通过IAP连接GCP Linux VM失败求助

解决Windows下VS Code通过IAP隧道连接GCP Linux VM失败的问题
  • 检查start-iap-tunnel命令参数
    确保命令格式正确,指定正确的VM名称、区域及端口映射:

    gcloud compute start-iap-tunnel [VM_NAME] 22 --local-host-port=localhost:2222 --zone=[ZONE]
    

    若跨区域连接,需补充--region参数,或确认gcloud默认区域配置正确。

  • 修正VS Code的SSH配置格式
    编辑Windows下的C:\Users\[你的用户名]\.ssh\config文件,注意Windows cmd的引号转义和参数格式:

    Host gcp-vm
        HostName localhost
        Port 2222
        User [VM登录用户名]
        IdentityFile "C:\Users\[你的用户名]\.ssh\google_compute_engine"
    

    或直接整合ProxyCommand(注意%p转义为%%p):

    Host gcp-vm
        HostName [VM名称/内部IP]
        User [VM登录用户名]
        ProxyCommand cmd /c "gcloud compute start-iap-tunnel %h 22 --local-host-port=localhost:%%p --zone=[ZONE]"
        IdentityFile "C:\Users\[你的用户名]\.ssh\google_compute_engine"
    
  • 检查VM的sshd用户访问配置
    通过成功的gcloud compute ssh登录VM,编辑/etc/ssh/sshd_config,确认AllowUsers或AllowGroups字段未限制当前连接用户,修改后重启sshd:

    sudo systemctl restart sshd
    
  • 排查本地端口占用
    在Windows cmd中执行以下命令,检查指定的本地端口是否被占用:

    netstat -ano | findstr :2222
    

    若端口被占用,更换为未使用的端口(如2223),同步更新VS Code配置和start-iap-tunnel命令的--local-host-port参数。

  • 更新Google Cloud SDK
    打开Google Cloud SDK Shell,执行命令更新到最新版本,避免兼容性问题:

    gcloud components update
    

内容的提问来源于stack exchange,提问作者location

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 06:52:39