代码之家  ›  专栏  ›  技术社区  ›  Agile Bean

gcloud compute ssh拒绝连接(返回代码255)

  •  9
  • Agile Bean  · 技术社区  · 8 年前

    症状:

    sudo gcloud compute ssh myuser@ubuntu
    ssh: connect to host 104.155.16.104 port 22: Connection refused
    ERROR: (gcloud.compute.ssh) [/usr/bin/ssh] exited with return code [255].
    

    我所做的:

    1: 验证端口22上的防火墙是否打开

    gcloud compute firewall-rules list
    

    返回

    NAME                    NETWORK  SRC_RANGES    RULES                         SRC_TAGS  TARGET_TAGS
    allow-rstudio           default  0.0.0.0/0     tcp:8787                                allow-rstudio
    default-allow-http      default  0.0.0.0/0     tcp:80                                  http-server
    default-allow-https     default  0.0.0.0/0     tcp:443                                 
    https-server
    default-allow-icmp      default  0.0.0.0/0     icmp
    default-allow-internal  default  10.128.0.0/9  tcp:0-65535,udp:0-65535,icmp
    default-allow-rdp       default  0.0.0.0/0     tcp:3389
    default-allow-ssh       default  0.0.0.0/0     tcp:22
    

    2: 续订公钥

    ssh-keygen -t rsa -f ~/.ssh/google_compute_engine -C myuser
    

    sudo gcloud compute ssh myuser@ubuntu
    Updating project ssh metadata...
    Updating project ssh metadata...done.                                                                                                                                     
    Waiting for SSH key to propagate.
    

    然后,仍然是相同的错误消息:

    ssh: connect to host 35.187.38.82 port 22: Connection refused
    ERROR: (gcloud.compute.ssh) [/usr/bin/ssh] exited with return code [255].
    

    我应该补充一点,直到今天我都可以访问ssh,当然,我之前用 gcloud验证登录

    SSH从谷歌云网页界面工作!有什么不同? 如果有任何帮助,我们将不胜感激!!

    4 回复  |  直到 8 年前
        1
  •  13
  •   Agile Bean    8 年前

    经过长时间的搜索,我终于找到了这个棘手问题的根本原因。我希望这将帮助一些绝望的人。。。

    您可能会拒绝ssh连接的原因是,意外删除了外部ip请求的内部路由。您可以通过以下方式进行检查:

    gcloud compute routes list
    

    如果未返回包含以下条目的列表:

    default-internet       default     0.0.0.0/0       default-internet-gateway 1000
    

    gcloud compute routes create default-internet \
    --destination-range 0.0.0.0/0 \
    --next-hop-gateway default-internet-gateway
    
        2
  •  1
  •   jason m    5 年前

    在我的例子中,我升级了GCP实例(只是添加了更多的处理器和内存)。

    我的Circle CI部署开始抛出:

    Authentication failed.
    
    Exited with code 255
    

    /etc/ssh/sshd_配置 毫无理由地被清空了。

    笔记 :PasswordAuthentication应设置为:

       PasswordAuthentication no
    
        3
  •  1
  •   jason m    5 年前

    以下内容对我来说具有一致性:

    gcloud init 然后通过

    结束。我希望这能帮助你,我亲爱的,互联网上的同病相怜者。

        4
  •  0
  •   Saran    5 年前

    我的场景是我在运行一个 nohup

    检查您是否能够 ping 您的实例。如果没有,请重新启动并 ssh ,它会很好地工作。这是解决方案之一。