Do you find it difficult to connect to your google cloud VM via SSH using ssh keys and you have to login to google cloud console frequently to start and stop your VM instances ?.
Google Cloud SDK productive tools come in handy not only to manage APIs and websites deployment but also to manage Google Cloud servers.
Many of us connect to google vm instances using several methods like connecting through a browser and access cloud instance directly from google console or connect to it using a SSH client with password authentication ( not secure and not recommended) and connect using generated and uploaded SSH keys to google console. But to take control of complete cloud instance management such as creating a cloud instance or starting a cloud instance etc., , one needs to login to google console or use google-cloud-sdk APIs.
Generating SSH keys and connecting to cloud servers using default MacOsX terminal may not be that convenient. I use iTerm2 in conjunction with google-cloud-sdk on my mac to manage google cloud services. Google-cloud-sdk can be installed on a mac OsX by downloading the package from google directly or with home brew command line utility .
Now let us see step by step procedure to install and configure google-cloud-sdk to manage cloud instances .
1.Install Home Brew package manager for mac osx
Installing homebrew is a straightforward process. It is as easy as just copy&paste a single line command in MacOsx terminal .
/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”
2.Install GoogleCloud SDK using brew
The next step is installing google-cloud-sdk . Google-cloud-sdk can be installed by directly downloading the package from google or with homebrew . I installed it using homebrew as I have already brew installed on my macosx .
brew install –cask google-cloud-sdk
gcloud init initiates google-cloud-sdk environment on mac OSX . If you encounter
gcloud : command not found error then you may have to copy below line in your ~/.bash_profile to let your mac OSX know the executable path . If you do not see .bash_profile in your home directory . You can create one and paste the line.
It may prompt for your google cloud login credentials for once .
3.Install and use iTerm SSH Terminal (optional)
Now we can connect to google cloud instances from your favourite terminal ( I use iTerm2) .
Let us see some of the commands to manage google cloud instance .
Useful Google Cloud Commands To manage VM instances
To connect to a cloud instance using ssh , enter below command .
gcloud compute ssh YourInstanceName
Start a VM instance with this command.
gcloud compute instances start YourInstanceName
you can start multiple instances at once .
gcloud compute instances start YourInstanceName1 YourInstanceName2
and to stop google cloud instances use the following command .
gcloud compute instances stop YourInstanceName1 YourInstanceName2