log/create tunneling connection using google compute ssh command
I recently discovered that it's possible to pass SSH flags using the gcloud compute ssh
command, which allows us to establish a tunneling connection. This is particularly useful because I wanted to connect to a database in Google Cloud Platform (GCP) without relying on an external IP address when using database client on my personal computer.
The command to achieve this is as follows:
1gcloud compute ssh YOUR_REMOTE_INSTANCE_NAME --project=YOUR_PROJECT_ID --zone=YOUR_ZONE -- -N -L LOCAL_PORT:DATABASE_HOST:DATABASE_PORT
Here's a breakdown of the command:
- The
--
is used to indicate the end ofgcloud
command options and the beginning of the SSH command options. This convention is common in many command-line utilities and serves to separate command-specific options from arguments. - The
-N
SSH option instructs the SSH client not to execute any commands on the remote server. This is especially useful when your sole objective is to establish an SSH tunnel and you don't need to initiate an interactive shell session. - The
-L
option in SSH is utilized for port forwarding, specifically local port forwarding. It enables you to create an SSH tunnel that forwards traffic from a specified local port on your machine to a specific host and port on the remote server.
However, in terms of security, I must emphasize that I'm uncertain about the safety and security of this method, so proceed with caution and take appropriate measures to ensure the security of your setup.