google-cloud-platformgoogle-compute-engineautossh

How to use autossh with google compute (`gcloud compute ssh`)


I would like to use autossh instead of the ssh command run by google cloud while doing gcloud compute ssh --zone myzone --project myproject mymachine

What is the command line to replace it?


Solution

  • A replacement for the command line

    Here is the two commands that allow you to use autossh:

    gcloud compute config-ssh
    autossh -M9042 mymachine.myzone.myproject 
    

    In my opinion, this is the easiest way to do it. The first line export the ssh key and configuration of your machines, and the second just use this alias.


    More on ssh configuration

    This also allow you to use the shortcut mymachine.myzone.myproject for scp, ssh, and all ssh related tools. Indeed, the list of your machines are exported in your ~/.ssh/config. This is a list of aliases you can also configure by hand.

    For more information on gcloud's config-ssh, you can refer to the official documentation.

    Notice that some shell environment will provide you with ssh command autocompletion, which is really helpful when it comme to remembering the name of your machines. Here is a reference for zsh.