How to Configure Google Compute Engine SSH Port Forwarding
You set up google compute engine ssh port forwarding by routing local ports through an encrypted SSH tunnel. This tunnel links a developer laptop to a private virtual machine without a public IP. Teams often rely on broad cloud roles to let engineers open these tunnels. When permissions are too wide, any developer can reach every internal port on that host. A single shared role gives full network reach across private databases and internal services. How google compute engine ssh port forwardin
SSH Agent Forwarding Security + End-to-End Encryption: the complete guide
Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.
You set up google compute engine ssh port forwarding by routing local ports through an encrypted SSH tunnel. This tunnel links a developer laptop to a private virtual machine without a public IP. Teams often rely on broad cloud roles to let engineers open these tunnels. When permissions are too wide, any developer can reach every internal port on that host. A single shared role gives full network reach across private databases and internal services.
How google compute engine ssh port forwarding works in practice
In a standard cloud network, virtual machines sit inside a private subnet. They do not have public IP addresses. To reach a web app or database on that machine, an engineer starts an SSH session. The client binds a local port on the laptop to a remote port on the virtual machine.
Google Cloud checks the user identity and cloud permissions before the session starts. It then pushes a temporary public key to the virtual machine metadata or guest agent. The OpenSSH daemon on the machine reads that key and lets the user log in. Some teams also use OpenSSH certificates signed by a Certificate Authority key. OpenSSH added certificate support for users and hosts in version 5.4. An OpenSSH certificate holds a public key, identity info, principal names, and signed options. It uses a much simpler format than standard TLS certificates.
Once the login succeeds, the SSH client opens a secure tunnel. Traffic sent to the local laptop port travels through the encrypted SSH channel. The remote server then sends that traffic to the target port on the cloud host. The engineer can now use local tools as if the remote service ran locally.
How SSH tunnels work with bastions and jump hosts
Many teams place a bastion or jump host at the edge of their cloud network. Engineers log in to the jump host first. Then they forward ports to deeper private machines. Admins can restrict what an OpenSSH certificate or key can do on that jump host. For example, certificate options can limit which ports or hosts a user can forward.
Still, managing these rules across many cloud machines takes constant work. If you do not set a validity window on an OpenSSH certificate, it lasts forever. Teams must rotate keys, update host configs, and track which internal IPs change over time. When a developer needs to check a single service, they often get full shell and tunnel rights.
SSH Agent Forwarding Security + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
What native port forwarding solves and what it misses
Native SSH port forwarding solves the network transport problem. It encrypts traffic in transit and keeps private ports off the public internet. You do not need to open firewall rules for every internal web port or database port. Cloud IAM roles and SSH keys control who can start the tunnel.
Still, a port forward is just a raw byte pipe. Once the tunnel opens, the SSH server cannot read what happens inside that pipe. The setup decides who logs in, not what individual queries or commands do in flight. If an engineer forwards a database port, the SSH log only shows an open channel. It does not record which tables the user read or which rows they deleted. Also, the developer still needs raw database passwords on their laptop to log in through the tunnel. Raw network tunnels also cannot rewrite sensitive fields like emails, phone numbers, or card numbers in query results.
Add command and file guardrails to SSH access
Host firewalls and certificate principals control who opens an SSH session. Yet an allowed user or agent can still run a bad one-shot command or pull sensitive files over sftp. In practice, hoop.dev sits inline on the host as an open-source SSH server with guardrails that uses OpenSSH certificates. For every one-shot command or sftp task an agent or human runs in production, hoop.dev decides to pass, mask, block, or escalate it for review.
Using hoop.dev SSH controls, guardrails check one-shot commands, env variable names, and sftp or scp paths before they run. Port forwards default to deny unless the target is listed. Because interactive shells have no statement boundary and carry no guardrails, teams can turn them off so every command is checked and logged. Check out the MIT-licensed project on GitHub.
Frequently asked questions
Does SSH port forwarding log the queries sent through the tunnel?
No, the SSH daemon only sees encrypted network packets passing through the forwarded port. It records when the tunnel opens and closes, but it never logs internal database queries or HTTP requests.
Do virtual machines need public IP addresses for SSH port forwarding?
No, machines can stay on private subnets without public IPs. Engineers can route their SSH traffic through an internal cloud tunnel or a dedicated jump host to reach the private machine.
Can OpenSSH certificates restrict port forwarding on a cloud host?
Yes, when you sign a user key with a Certificate Authority key, you can attach certificate options. These options can disable port forwarding entirely or limit which specific ports a user can forward.
Related guides
In this post