SSH port-forwarding from within the Google Cloud Shell

Google provides a very useful tool especially for those I’m calling “cloud workers”: the Cloud Shell. This gives you access to a linux-shell for just whatever you do usually in a linux shell - directly from your browser.

From time to time I use the cloud shell as a starting-point to connect via ssh to other systems. Recently I noticed that tcp-port-forwarding via the outgoing ssh-connections doesn’t work out of the box: When trying to establish a port-forwarding (ssh user@targethost -L 8080:127.0.0.1:8080) the following error occurs:

bind: Cannot assign requested address

… and the port-forwarding doesn’t work.

The reason for this is simple - as always as you know it: The ssh-client tries to bind to the local ipv6-port. This is not supported in the cloud shell and therefore fails.

Solving the problem

To change this behavior, you can add the commandline-switch “-4” to force ssh to only use ipv4-sockets. If you change the above command-line to

ssh user@targethost -L 8080:127.0.0.1:8080 -4

the port-forwarding works as expected.

In case you want to disable ipv6 for all outgoing ssh-connections from Google cloud shell, simple add the following configuration to your ssh-config:

~/.ssh/config

Host *
    AddressFamily inet

Wanna take an unfair advantage?

ToolboxCoverSmall

If it comes to working on the Linux command line - at the end of the day it is always about knowing the right tool for the right task.

And it is about knowing the tools that are most certainly available on the Linux system you are currently on.

To give you all the tools for your day-to-day work at the Linux command line, I have created “The ShellToolbox”.

This book gives you everything

  • from the very basic commands, through
  • everything you need for working with files and filesystems,
  • managing processes,
  • managing users and permissions, through
  • software management,
  • hardware analyses and
  • simple shell-scripting to the tools you need for
  • doing simple “networking stuff”.

Everything in one single, easy to read book. With explanations and example calls for illustration.

If you are interested, go to shelltoolbox.com and have a look (as long as it is available).