2017-02-10 96 views
1

我已經在一個新項目上設置了一個新的Google Compute Engine實例。我啓動實例並使用命令gcloud init連接到我的項目。然後我使用命令sudo gcloud compute ssh instance-1。這需要我通過SSH密鑰對生成:無法通過SSH連接到Google計算引擎

WARNING: The private SSH key file for Google Compute Engine does not exist. 
WARNING: You do not have an SSH key for Google Compute Engine. 
WARNING: [/usr/bin/ssh-keygen] will be executed to generate a key. 
Generating public/private rsa key pair. 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/username/.ssh/google_compute_engine. 
Your public key has been saved in /Users/username/.ssh/google_compute_engine.pub. 
The key fingerprint is: 
SHA256:there_is_a_key_here_but_probably_should_not_show_it [email protected] 
The key's randomart image is: 
+---[RSA 2048]----+ 
|     | 
|     | 
|     | 
|     | 
|     | 
|     | 
|     | 
|There is an image| 
|here    | 
+----[SHA256]-----+ 
Updating project ssh metadata...\Updated [link to the project]. 
Updating project ssh metadata...done.               
Warning: Permanently added 'compute.1788786712041991164' (ECDSA) to the list of known hosts. 
Permission denied (publickey). 
Permission denied (publickey). 
Permission denied (publickey). 
Permission denied (publickey). 
Permission denied (publickey). 
Permission denied (publickey). 
Permission denied (publickey). 
Permission denied (publickey). 
Permission denied (publickey). 
Permission denied (publickey). 
Permission denied (publickey). 
Permission denied (publickey). 
Permission denied (publickey). 
ERROR: (gcloud.compute.ssh) Could not SSH to the instance. It is possible that your SSH key has not propagated to the instance yet. Try running this command again. If you still cannot connect, verify that the firewall and instance are set to accept ssh traffic. 

奇怪。我檢查了我的Google雲端控制檯中的元數據,運行此命令後,它們出現在那裏。所以成功生成並更新了元數據。 我稍等一會兒,然後再次嘗試相同的命令:

My-MacBook-Air-4:~ myname$ sudo gcloud compute ssh instance-1 
Permission denied (publickey). 
ERROR: (gcloud.compute.ssh) [/usr/bin/ssh] exited with return code [255]. See https://cloud.google.com/compute/docs/troubleshooting#ssherrors for troubleshooting hints. 

所以我嘗試了一些故障排除提示的:

gcloud compute firewall-rules list 

NAME     NETWORK SRC_RANGES RULES       SRC_TAGS TARGET_TAGS 
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 

防火牆似乎罰款。這發生在我在任何項目上創建的每個Google Compute Engine實例上。我不明白髮生了什麼,密鑰對已經創建,我在幾個不同的項目上多次嘗試了所有的步驟,錯誤仍然存​​在。

編輯:鍵出現在項目的SSH選項卡中,元數據選項卡仍是空的。

+0

Stack Overflow是編程和開發問題的網站。這個問題似乎與題目無關,因爲它不涉及編程或開發。請參閱幫助中心的[我可以詢問哪些主題](http://stackoverflow.com/help/on-topic)。也許[超級用戶](http://superuser.com/)或[Unix&Linux堆棧交換](http://unix.stackexchange.com/)會是一個更好的地方。另請參閱[我在哪裏發佈有關Dev Ops的問題?](http://meta.stackexchange.com/q/134306) – jww

回答

2

然後我用命令sudo gcloud compute ssh instance-1

使用sudo是錯在這裏。看起來您已經在/Users/username/.ssh/google_compute_engine中創建了一個密鑰,但由於它的註釋[email protected]可能是由錯誤的所有權(即由root擁有)創建的。

您可能能夠與解決這個問題了:

sudo chown $USER:$GROUPS ~/.ssh/google_compute_engine{,.pub} 

然後連接沒有sudo

gcloud compute ssh instance-1 

或者如果失敗只是重新開始,但沒有爲任何東西使用sudo

+0

$ USER的值是什麼:$ GROUPS?對不起,不太熟悉那個命令 –

+0

只需按照原樣運行命令,那些變量就會擴展到您的用戶名和組。這與運行'chown ilapan:staff'(或者你的用戶名可能是什麼)相同 –

+0

它的工作原理!謝謝 –