2017-07-18 203 views
0

我无法获得SSH访问到由谷歌云命令行工具(gcloud)创建的虚拟机实例。gcloud计算SSH连接拒绝(返回代码255)

症状:

sudo gcloud compute ssh [email protected] 
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 

3:更新元数据与新的公用密钥

sudo gcloud compute ssh [email protected] 
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从谷歌云前W做认证eb接口工作!那里有什么不同? 将不胜感激的任何帮助!

+0

的https: //stackoverflow.com/documentation/ssh/2926/debugging-ssh-problems/18370/connection-refused#t=201707181333474083302 – Kenster

+0

对谁降级人:这将是巨大的,提供一个智能提示,为何特定错误messag即使端口22打开,“连接被拒绝”也会显示! –

+0

@Kenster谢谢你的有趣的联系。不幸的是,我已经完成了所有的建议(使用-vvv,替换了ssh密钥)。此外,除了显而易见的防火墙端口被关闭之外,对于特定错误消息“连接混乱”没有答案。 –

回答

2

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

的原因,你可能会得到您的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