Cannot connect to Compute Engine instance via SSH

萝らか妹 提交于 2020-01-22 07:55:07

问题


I've just created an instance using Google Cloud Platform's Compute Engine and tried to connect to it via SSH connection but it failed.

I'm following the quick start here.

I have generated the SSH key on my PC and have entered the pass-phrase when asked. Though I fail to succeed a log in :-(

I got the PuTTY SSH's error as below snapshots.

Then I get the PuTTY window inactive.


回答1:


I have the same problem but found a workaround to connect via PuTTY manually.

In brief

  1. Generate SSH key for the machine instance
  2. Add SSH public key to the instance
  3. Prepare to log in - acquiring information for IP, login name, pass phrase, private SSH key
  4. Connect to the instance via SSH client, e.g. PuTTY in Windows

Detail steps

For me the gcloud quick start had already:

  • launched my instance
  • created my public and private RSA keys (in C:\Users\USER_NAME\.ssh\)

Public Key - C:\Users\USER_NAME\.ssh\google_compute_engine.pub

Private Key - C:\Users\USER_NAME\.ssh\google_compute_engine.ppk

  1. Go to the Google Developers Console in your browser
  2. Select your project and in the left hand nav bar click: Compute -> Compute Engine -> VM instances
  3. Your running instance(s) will be linked below the CPU usage chart
  4. Click the one you want and find the Add SSH key link and click it
  5. Paste the entire contents of google_compute_engine.pub into the field that appears
  6. Click Save and after a few seconds the key details will appear on the page (if you get an error you pasted from the wrong key file or didn't copy all the text)
  7. The first word in those details is your (case sensitive) username

  1. Find the External IP above on the page
  2. Open PuTTY and paste the external IP into Host Name (port is the default of 22)

  3. In the left hand nav expand: Connection -> SSH and then click Auth

  4. Next to "Private key file for authentication" click "Browse"
  5. Select "C:\Users\USER_NAME\.ssh\google_compute_engine.ppk" and click Open
  6. Scroll the left hand nav back up and click the top item "Session"
  7. Under "Saved Sessions" enter a name and click "Save"
  8. Accept the warning message and you should be prompted to login with the username from above step
  9. Input your passphrase
  10. Done

Hope this helps. If someone has a solution for the gcloud issue I'd love to hear it too.




回答2:


A non-discussed answer is that you should have at least the standard memory on your VM instance (3.75GB) - do NOT use Micro VM instances.

I could only log in with SSH via browser console or gcloud command line, but not with Putty or Mac terminal SSH. I spent an hour on the phone with support and we found this to be the problem.




回答3:


To get identified by ssh you need to run this command, which add gcloud ssh key in the list of ssh keys

ssh-add google_compute_engine C:\Users\USER_NAME\.ssh\



回答4:


You can also connect to your VM instance using embedded in-browser SSH client, see here for how to do that. That's pretty much a couple of mouse click to do.




回答5:


Not sure why, if the user already existed (eg: already SSH logged in google web console), it doesn't work when I manually added SSH keys into metadata on google web console. I have tried hundred of times from the steps below.

I found out you have to manually add your ssh key through web SSH CONSOLE -> ssh in on google web console and copy ssh pub key on your local machine (usually is in ~/.ssh/) and append (edit and paste to the end) it to ~/.ssh/authorized_keys.




回答6:


1) SSh into the vm by cloud console.

2) Change the root password sudo passwd

3) set below parameters to yes by nano /etc/ssh/sshd_config

PasswordAuthentication PermitRootLogin PasswordAuthentication

4) restart sshd service sshd restart



来源:https://stackoverflow.com/questions/25784408/cannot-connect-to-compute-engine-instance-via-ssh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!