Keywords: General - Google Cloud Platform - Technical issue - Connectivity (SSH/FTP)
I've seen multiple posts around the web and two in particular in this community without a proper solution to when sshd service is unable to run, I believe because it just can't make it when instance starts. When this happens, users are unable to SSH to any instance because of this error referenced in google documentation.
This is painful and frustrating as you can see in previous references:
link to community post
Thus I decided to build this topic explaining a simple fix:
Go to the VM instances page and click on the Instance name of your VM.
Click the Edit button at the top of the page.
Under Custom metadata, click Add item.
Set 'Key' to 'startup-script' and set 'Value' to this script:
useradd -G sudo USERNAME
echo 'USERNAME:PASSWORD' | chpasswd
Enable "Enable connecting to serial ports" by checking the box below the SSH button.
Click Save and then click RESET on the top of the page. Wait for some time for the instance to reboot.
Click on 'Connect to serial port' in the page. In the new window, you might need to wait a bit and press on Enter of your keyboard once; then, you should see the login prompt.
Login using the USERNAME and PASSWORD you provided.
Check for Firewall status
sudo ufw status
NOTE: it may be clear that no
22/tcp or no
OpenSSH ALLOW Anywhere are active
Open SSH Port
sudo ufw allow ssh
sudo ufw status
NOTE: You should see something like
To Action From
-- ------ ----
Nginx HTTP ALLOW Anywhere
Nginx HTTPS ALLOW Anywhere
22/tcp ALLOW Anywhere
Nginx HTTP (v6) ALLOW Anywhere (v6)
Nginx HTTPS (v6) ALLOW Anywhere (v6)
22/tcp (v6) ALLOW Anywhere (v6)
Be happy ssh-ing again as normal.