0

I am trying to connect to my Google Cloud VM instance through SSH. I didn't have any problem before I mounted a new 500GB zonal persistent disk and even then I was able to ssh and format the disk and use the GCP instance. I stopped my instance yesterday from GCP GUI and now I cannot ssh using the external IP. How can I fix this ssh problem? My instance is started and running.

$ ssh external_IP_addr
ssh: connect to host external_IP_addr port 22: Connection refused
$ sudo nmap -Pn -p 22 external_IP_addr
Starting Nmap 7.80 ( https://nmap.org ) at 2021-02-09 15:44 EST
Nmap scan report for XYZ.bc.googleusercontent.com (ABC)
Host is up (0.099s latency).

PORT   STATE  SERVICE
22/tcp closed ssh

Nmap done: 1 IP address (1 host up) scanned in 0.28 seconds

and

$ gcloud compute instances add-metadata myvm \
>     --metadata=serial-port-enable=1
ERROR: (gcloud.compute.instances.add-metadata) Could not fetch resource:
 - The resource 'projects/rare-origin-289023/zones/us-west1-b/instances/myvm' was not found

These are the commands I used for formatting the disk and mounting it and it was actually usable and I ran experiments using it:

$ sudo mkfs.ext4 -m 0 -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/sdb
$ sudo mkdir -p /mnt/disks/mona
$ sudo mount -o discard,defaults /dev/sdb /mnt/disks/mona
$ sudo chmod a+w /mnt/disks/mona
$ sudo cp /etc/fstab /etc/fstab.backup
$ sudo blkid /dev/sdb
$ echo UUID=`sudo blkid -s UUID -o value /dev/sdb` /mnt/disks/mona ext4 discard,defaults,NOFAIL_OPTION 0 2 | sudo tee -a /etc/fstab
$ cat /etc/fstab
# /etc/fstab: static file system information
UUID=02132fe0-5012-49f4-8143-2fc1dbfad2b4 / ext4 rw,discard,errors=remount-ro,x-systemd.growfs 0 0
UUID=F77B-E04A /boot/efi vfat defaults 0 0
UUID=8f48ff56-d347-420a-9cfd-280a35e643eb /mnt/disks/mona ext4 discard,defaults,NOFAIL_OPTION 0 2
$ ls /mnt/disks/mona/
total 24
drwx------ 2 root root 16384 Feb  8 20:29 lost+found
drwxrwxrwx 3 root root  4096 Feb  8 20:29 .
drwxr-xr-x 3 root root  4096 Feb  8 20:30 ..

The instance runs Ubuntu 18.04 and I have Ubuntu 20.04 on my local machine.

Using the Web console in GCP GUI also doesn't connect via SSH. enter image description here

Mona Jalal
  • 433
  • 2
  • 5
  • 13
  • 1
    Is the sshd running at all? It appears not, or perhaps it is running and not listening at the expected address or port. Use `ss -lntp` to find out. – berndbausch Feb 09 '21 at 21:55
  • @berndbausch do you mean at the GCP instance or local machine? It is running on local machine but how can I access remote machine to tell that? – Mona Jalal Feb 09 '21 at 21:56
  • The instance. If the sshd is not running, there is nothing you can connect to. You check this in the instance's console. The `nmap` output is an indication that it is not running, by the way. – berndbausch Feb 09 '21 at 22:54
  • However, the output of `gcloud` seems to say that the instance does not exist at all. You may want to clarify that first. – berndbausch Feb 09 '21 at 23:04
  • By "console", I meant a graphics console. Not sure if GCP supports that, but you can connect to the serial console of an instance: https://cloud.google.com/compute/docs/instances/interacting-with-serial-console. – berndbausch Feb 09 '21 at 23:08
  • yes even the GCP console doesn't work as seen in the screenshot in the OP since the boot is damaged. problem was not using `nofail` and by mistake using `NOFAIL_OPTION` – Mona Jalal Feb 09 '21 at 23:29
  • Check this official [SSH troubleshooting documentation](https://cloud.google.com/compute/docs/troubleshooting/troubleshooting-ssh) from GCP. There are several troubleshooting methods you can try on that guide. – Alex G Feb 10 '21 at 06:15

0 Answers0