Unable to login to a GCP VM machine: kex_exchange_identification: Connection closed by remote host

Viewed 1533

I am trying to login to a VM machine but unable to get in there as the below error pops up:

ERROR: (gcloud.beta.compute.start-iap-tunnel) Error while connecting [[Errno 1] Operation not permitted].
kex_exchange_identification: Connection closed by remote host
ERROR: (gcloud.beta.compute.ssh) [/usr/bin/ssh] exited with return code [255].

Command used to log in:

gcloud beta compute ssh --zone "us-east1-b" "user1@test"  --project "my-test-project"

When I use the same command from a different machine then it allows me to login to the test VM.

I have been looking at possible solutions related to the firewall settings but unable to get success. Can anyone help here ?

1 Answers

I try to connect with an instance with the command that you post and worked for me when I use it from the cloud shell and from another instances. The error that is given to you could happen for different reason, which are:

  • The VM is booting up and sshd is not running yet. You can't connect to a VM before it is running. To resolve this issue, wait until the VM has finished booting and try to connect again.

  • The firewall rule allowing SSH is missing or misconfigured. By default, Compute Engine VMs allow SSH access on port 22. If the default-allow-ssh rule is missing or misconfigured, you won't be able to connect to VMs. To resolve this issue, Check your firewall rules and re-add or reconfigure default-allow-ssh.

  • sshd is running on a custom port. If you configured sshd to run on a port other than port 22, you won't be able to connect to your VM. To resolve this issue, create a custom firewall rule allowing tcp traffic on the port that your sshd is running on using the following command:

    gcloud compute firewall-rules create FIREWALL_NAME --allow tcp:PORT_NUMBER
    
  • Your custom SSH firewall rule doesn't allow traffic from Google services. SSH connections from the Cloud Console are refused if custom firewall rules do not allow connections from Google's IP address range. To solve this issue visit this link

  • The sshd daemon isn't running or isn't configured properly. The sshd daemon enables SSH connections. If it's misconfigured or not running, you can't connect to your VM. To resolve this issue, review the user guide for your operating system to ensure that your sshd_config is set up correctly.

Related