How to Port Forward Using the Gcloud SDK
A reference on how to forward ports with the Google Gcloud SDK.
- A tunnel that creates a background listening port on locahost and releases the terminal
glcoud compute ssh <your-vm> \
--project=<gcp project id> \
--zone <gce vm zone> \
-- -L 8888:localhost:8888 -N -q -f
Syntax | Comment |
---|---|
-- |
commands to supply to ssh |
-L 8888:localhost:8888 |
local port forwarding. a port on my computer, localhost:8888 is redirected to port 8888 on destination |
-N |
Do not execute a remote command. This is useful for just forwarding ports (protocol version 2 only). |
-q |
Quiet mode. Causes most warning and diagnostic messages to be suppressed. |
-f |
Requests ssh to go to background just before command execution. Implies -n . . -n Redirects stdin from /dev/null (actually, prevents reading from stdin). |