Search code examples
servergoogle-cloud-platformvirtual-machineubuntu-server

Google cloud: I can not acces to my VM


I have problem with a google cloud virtual machine Suddenly I am not able to acces to my VM instance from google cloud: it returs me: ssh: connect to host port 22: Connection refused

I have run nmap and outputs Host is up. PORT STATE SERVICE 22/tcp filtered ssh

I have modified the /etc/ssh/ssh_config, to prevent broken pip error, adding :

ServerAliveInterval 120

ServerAliveCountMax 10

to the end of that file .

1.: May anyone figuer out what is happening and how to solve it.

  1. Is there any way alternative to ssh to connect to my VM instance?

thanks so much


Solution

  • Summary from the comments above:


    1. Set a password to a user within the instance by setting up an startup script on the GCE instance.
      • To add an startup script to a GCE instance:
        • Click on the name of the instance.
        • Click edit.
        • Set custom metadata like this:
          • Key startup-script
          • Value #!/bin/bash echo -e "linuxpassword\nlinuxpassword" | passwd linuxuser**

    If you've never set a password for either your user or root you'll be asked twice for a new password, if you've set a password before you'll be asked first for the old password and then twice for the new password, so take this in account when using the startup script. As explained here the script to set the password can be run with or without --stdin parameter depending on the system you run the script on.

    1. Access the instance via Interactive Serial Console.

    2. Revert the settings on the file /etc/ssh/ssh_config back to the old config and try to ssh again.

    3. Important note, for security reasons remove the startup script and change the password from within the instance once you regain access to the instance.