SSH : PORT 22 CONNECTION ISSUE SOLVED

Diana Moraa
2 min readFeb 11, 2022

--

This error can occur for several reasons. The following are some of the most common causes of the errors:

  • 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

SOLUTION

  1. Shut down the instance
  2. Click ‘Edit’ for the instance
  3. Under ‘Custom Metadata’ section, add ‘startup-script’ key, with value:

#! /bin/bash sudo ufw allow 22

4. Save

5. Start the instance again, and SSH into it

GENERAL RECOMMENDATIONS.

  • Make sure the disk resize is done properly.
  • Confirm the instance has fully booted up. You can confirm this through VM serial console output.
  • Once the instance is booted confirm if ssh daemon is running. Serial console output will have information about ssh daemon. If the ssh service is not running you can use an interactive serial console to start the service.
  • Make sure you have firewall rules configured in the GCE network to allow ssh port.
  • Make sure the firewall on the instance(e.g. iptables) is allowing the ssh port. You can use an interactive serial console to disable the firewall on the VM, if required.

--

--

Diana Moraa
Diana Moraa

Written by Diana Moraa

Passionate and motivated about Cloud Computing technology because it continues to allow us to modernize, consolidate IT infrastructure and automate workloads.

No responses yet