Cannot connect to VM (GCE) using SSH

Solution 1:

This question is 3 years old, but I posted my answer for anybody who is facing similar issues. At first, please have a look at the serial port messages:

[34987645.859165] Out of memory: Kill process 24241 (python2) score 326 or sacrifice child
[34987645.867298] Killed process 24241 (python2) total-vm:250432kB, anon-rss:204628kB, file-rss:0kB
Sep  2 08:16:18 instance-1 kernel: [34987645.059900] sshd invoked oom-killer: gfp_mask=0x201da, order=0, oom_score_adj=-1000
Sep  2 08:16:18 instance-1 kernel: [34987645.067997] sshd cpuset=/ mems_allowed=0
...
Sep  2 08:16:18 instance-1 kernel: [34987645.859165] Out of memory: Kill process 24241 (python2) score 326 or sacrifice child
Sep  2 08:16:18 instance-1 kernel: [34987645.867298] Killed process 24241 (python2) total-vm:250432kB, anon-rss:204628kB, file-rss:0kB

if you see messages like these: Out of memory , sshd invoked oom-killer and so on, that means that your server is running out of free memory.

To solve this issue you should shutdown your VM instance, change its machine type to another one with more memory or use custom, then save changes and and start your VM. In addition, you can use Cloud Monitoring to be aware about resource usage of your VM.