I create ssh pub/private keys to access the remote VM. I copied the public keys in the VM ssh config and was able to access the VM very fine. After a few days, it just stopped working and I was getting the connection time out. I tried every things configuration so that I can reconnect it but nothing works. This includes creating new ssh keys, deleting and creating a new VM, and changing AZ, but nothing works.
But I don't know why but I switched to another wifi network (which is basically the same router but with 2.4 GHz and earlier was 5GHz) and tried to connect and surprisingly It worked. But I don't know the reason behind it. Does anyone have any idea about it?
It could be because of a variety of reasons, but if after you changed your network it works, the issue could be related to your old network configuration.
I found this answer in SO that might be related to your issue. VC Code can't SSH into Google Cloud
But what could be the reason, as I was getting connection time out from the server. It seems the server is blocking my request. Also, the network is the same but the band is different. So, I was on the same network.