Use cases · Published 2026-11-16
SSH Port 22 Open on GCP vs Azure: 12 Hours of Logs
The same 12-hour SSH experiment on Google Cloud, with the full Terraform lab, compared with two Azure VMs: first knock, root attempts and fail2ban bans.
Our first post, What Happens When You Expose SSH to the Internet, left two key-only servers on Azure open for a night. A fair question from the back row: is that just Azure? Does another cloud get a different crowd? So we repeated the experiment on Google Cloud the next night and put the numbers side by side.
TL;DR
- Port 22 open to the world on GCP looked like it did on Azure. Key-only sshd, no
Failed passwordline, nobody got in. - GCP's first hostile line came 10 minutes 22 seconds after the VM was running, then nothing for 29 minutes. Azure's first lines came within minutes; we did not time them.
- One network did most of the fail2ban work. Of 44 networks seen, one was banned, eight times.
- Two networks showed up on both clouds among the busiest:
45.148.10.0/24and80.94.92.0/24. - Not tested: the RHEL family on GCP. The RHEL numbers below are the Azure ones.
The setup, and the trap in the default network
One e2-micro in us-central1, Ubuntu 26.04.1 with OpenSSH 10.2p1, key only. fail2ban 1.1.0 with a systemd journal match, as on the Azure Ubuntu server.
The first decision was the network. A new Google Cloud project already carries a default-allow-ssh rule that allows tcp:22 from 0.0.0.0/0. On that network port 22 is open before you do anything, so "minutes since the rule opened" would mean nothing. We built a small custom VPC with no rules except our one SSH rule, which is the experiment.
Everything was created with Terraform. This is the code that ran, with a comment line added at the top:
# main.tf: custom VPC, one world-open tcp:22 rule, one e2-micro (the code that ran)
terraform {
required_version = ">= 1.9"
required_providers {
google = {
source = "hashicorp/google"
version = "~> 7.0"
}
}
}
variable "project" {
type = string
description = "GCP project id"
}
variable "zone" {
type = string
default = "us-central1-a"
}
provider "google" {
project = var.project
region = "us-central1"
zone = var.zone
}
locals {
labels = { obf-lab = "true" }
}
resource "google_project_service" "compute" {
service = "compute.googleapis.com"
disable_on_destroy = false
}
# A small custom network: the default network already ships a
# default-allow-ssh rule, which would hide the moment we open the port.
resource "google_compute_network" "obf" {
name = "obf-net"
auto_create_subnetworks = false
depends_on = [google_project_service.compute]
}
resource "google_compute_subnetwork" "obf" {
name = "obf-subnet"
region = "us-central1"
network = google_compute_network.obf.id
ip_cidr_range = "10.77.0.0/24"
}
# Intentional: SSH open to the whole internet. This is the experiment.
resource "google_compute_firewall" "ssh_open" {
name = "obf-allow-ssh-world"
network = google_compute_network.obf.name
direction = "INGRESS"
source_ranges = ["0.0.0.0/0"]
target_tags = ["obf-ssh"]
allow {
protocol = "tcp"
ports = ["22"]
}
}
resource "google_compute_instance" "web1" {
name = "obf-web1"
machine_type = "e2-micro"
zone = var.zone
tags = ["obf-ssh"]
labels = local.labels
boot_disk {
initialize_params {
image = "ubuntu-os-cloud/ubuntu-2604-lts-amd64"
size = 10
type = "pd-standard"
labels = local.labels
}
}
network_interface {
subnetwork = google_compute_subnetwork.obf.id
access_config {} # ephemeral external IP, no static address
}
metadata = {
ssh-keys = "obfadmin:${trimspace(file("${path.module}/obf_key.pub"))}"
enable-oslogin = "FALSE"
}
metadata_startup_script = file("${path.module}/startup.sh")
# Cost safety net: GCP deletes the VM itself after 14 hours.
scheduling {
max_run_duration {
seconds = 50400
}
instance_termination_action = "DELETE"
provisioning_model = "STANDARD"
on_host_maintenance = "MIGRATE"
}
depends_on = [google_compute_firewall.ssh_open]
}
output "public_ip" {
value = google_compute_instance.web1.network_interface[0].access_config[0].nat_ip
}The startup script installs fail2ban and makes the journal persistent:
#!/bin/bash
# startup.sh: installs fail2ban and keeps the journal (the code that ran, this comment line added)
# obf-lab startup script (runs as root at every boot; guarded to run once)
[ -f /var/lib/obf-marker ] && exit 0
export DEBIAN_FRONTEND=noninteractive
echo "startup_script_start_utc=$(date -u +%Y-%m-%dT%H:%M:%SZ) ssh_listening=$(ss -tln | grep -c ':22 ')" > /var/lib/obf-marker-start
# journald persistent
mkdir -p /var/log/journal /etc/systemd/journald.conf.d
printf '[Journal]\nStorage=persistent\n' > /etc/systemd/journald.conf.d/obf-persistent.conf
systemctl restart systemd-journald
apt-get update -q
apt-get install -y -q fail2ban nftables
mkdir -p /etc/fail2ban
cat > /etc/fail2ban/jail.local <<'EOF'
[DEFAULT]
banaction = nftables
[sshd]
enabled = true
backend = systemd
journalmatch = _SYSTEMD_UNIT=ssh.service + _COMM=sshd
EOF
systemctl enable fail2ban
systemctl restart fail2ban
{
echo "startup_script_done_utc=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
echo "ssh_listening=$(ss -tln | grep -c ':22 ')"
echo "uptime_since_utc=$(uptime -s)"
} > /var/lib/obf-markerThe journalmatch line is what ran, to match the Azure Ubuntu server (web1). It is not a recommendation: on Ubuntu 26.04 the logging process is sshd-session, so the match only works through the unit part.
The first apply failed
The first plan had on_host_maintenance = "TERMINATE". The network, subnet and firewall rule were created, then the VM was refused:
# Real output, excerpt: first apply, attempt 1
google_compute_firewall.ssh_open: Creation complete after 13s [id=projects/<project>/global/firewalls/obf-allow-ssh-world]
google_compute_instance.web1: Creating...
Error: Error creating instance: googleapi: Error 400: e2 instances do not support onHostMaintenance=TERMINATE unless they are preemptible., badRequeste2 machines only allow TERMINATE when they are preemptible. We switched to MIGRATE and dropped automatic_restart = false. The second apply took 22 seconds. The firewall rule therefore existed about 3 minutes before the VM, with nothing listening, so those minutes are not in the window.
The max_run_duration block, a 14 hour cost safety net, was accepted and stored by the API. It never fired: we destroyed the VM after 12 hours 14 minutes, so whether it really deletes the VM is untested.
The first knock, then silence
The VM was running at 18:23:34 UTC. The first hostile line arrived at 18:33:56, 10 minutes 22 seconds later: a connect and close with no authentication attempt, typical of a scanner that only looks at the banner. The second hostile line came at 19:03:19. After that there was no hour without lines.
Azure showed hostile lines within minutes. This was one visitor trying the handle, going for a coffee and coming back.
The night in numbers
Collected 12 hours 13 minutes after the VM started, with our own lines removed:
- 463 hostile-side lines from 59 addresses in 44 /24 networks.
- 255 lines naming
root, 63Invalid userlines. Failed passwordandFailed publickey: 0 and 0. As in the first post, a key-only server has nobody to fail a password.- 334 lines with
[preauth], 53 closes before any user was named, 8no matching key exchange method. - No
Acceptedline from anyone but us, no new users, oneauthorized_keysfile, no root crontab.
Three addresses wrote 82, 70 and 62 lines: 214 of 463, close to half. One /24 alone wrote 144 lines. A good part of this night was a few very enthusiastic scripts.
fail2ban: counts the strangers, ignores root
# Real output, excerpt: fail2ban-client status sshd after 12 hours
Status for the jail: sshd
|- Filter
| |- Currently failed: 1
| |- Total failed: 63
| `- Journal matches: _SYSTEMD_UNIT=ssh.service + _COMM=sshd
`- Actions
|- Currently banned: 0
|- Total banned: 8Total failed is 63, exactly the number of Invalid user lines. The default filter counted attempts with an unknown user name and none of the 255 lines naming root.
All 8 bans were for one /24 (two addresses). Each ban lasted the default 10 minutes, and the same source came back 6 to 9 minutes after each unban. One network out of 44 was banned. fail2ban did its job, politely, to a visitor who treated the ban as a short coffee break.
Side by side
Different nights (Azure 12 to 13 November, GCP the night after), different regions, one host per column. Azure web2 ran a different fail2ban setup (firewalld ban action, its own journal match), so its ban count is not the same configuration as the other two.
| Azure web1 (Ubuntu 26.04.1) | Azure web2 (RHEL 10.2) | GCP obf-web1 (Ubuntu 26.04.1) | |
|---|---|---|---|
| Hostile-side lines | 215 | 409 | 463 |
| Distinct sources / /24 networks | 49 / 40 | 68 / 55 | 59 / 44 |
Lines naming root | 97 | 166 | 255 |
Invalid user lines | 14 | 48 | 63 |
Failed password / Failed publickey | 0 / 0 | 0 / 0 | 0 / 0 |
| fail2ban bans | 2 | 1 | 8 (one /24) |
| Networks banned / seen | 2 / 40 | 1 / 55 | 1 / 44 |
Azure lines exclude those from our own /24; GCP lines exclude every session process that handled our address. The two methods are close but not identical.
Two networks appear among the busiest on both clouds: 45.148.10.0/24 (21 lines on web1, 46 on web2, 38 on GCP) and 80.94.92.0/24 (27, 27, 19).
We do not read this as one cloud being more attacked than the other. Each column is one host on one night. What repeats is the shape: key-only sshd never evaluates a password or a key, most lines are pre-auth closes, many of them naming root, and the default fail2ban filter counted mostly unknown-user attempts (on GCP exactly the 63 Invalid user lines).
Cleanup
terraform destroy removed all 5 resources. A read-only check afterwards listed 0 instances, 0 networks and subnets, 0 disks, 0 external addresses and nothing labeled obf-lab. The Compute API stays enabled in the project (disable_on_destroy = false), which costs nothing.
What we have not verified
- The counts are one 12-hour window per cloud, on different nights and in different regions. They are a shape, not a rate.
- RHEL was not run on GCP. The RHEL-family numbers here are the Azure web2 ones.
- Whether
max_run_durationdeletes the VM at 14 hours: not tested. - Three addresses wrote close to half of the GCP lines, so the totals depend heavily on a few sources.
- No geolocation or ASN lookup. The /24 groupings are by prefix, not by owner.
- No password login was allowed, so we know nothing about what a weak password would cost.
- Free-tier billing was not read back, and internet egress was not measured.
Related guides
- Troubleshoot Linux firewall access safely: narrow port 22 to your own address without locking yourself out.
- Inspect Linux service logs with journalctl: read the
sshdlines this article counts. - Troubleshoot SSH connection refused on Linux: what to check when you cannot connect.
Sources
- sshd_config(5)
- Terraform Google provider: google_compute_instance
- Observation notes: one Google Cloud test VM, 13 November 2026 18:23 UTC to 14 November 2026 06:37 UTC.
More from the blog
- What Happens When You Expose SSH to the Internet · Use cases, 2026-11-13
- Run an AI Coding Agent Against Infrastructure Safely · Use cases, 2026-11-05
- Backup Monitoring with Heartbeat Checks: Dead Man's Switch, Exit-Status Alerts and Restore Tests · Use cases, 2026-11-01
This article is educational information, not incident-response or legal advice. Verify package status with your operating system, hosting, or runtime vendor.