This steps is working for Mac and Linux Operating System.
Step 1: Create a SSH Key using the following command:-
ssh-keygen -t rsa -f ~/.ssh/gcloud_vm -C vedant
where gcloud_vm = key name file and vedant = username
Step 2: Open the public key file using the following command:-
cd ~/.ssh && cat gcloud_vm.pub
Step 3: Login into the google cloud platform and click on Edit on VM instance details icon, go down and find SSH key section.
Step 4: Copy the public key and paste it in the enter key data and save it.
Step 5: Now open the terminal and login into your instances using the following command:
ssh -i gcloud_vm [email protected]
Where gcloud_vm is the private key file in .ssh directory and ipaddress is your external IP of your VM Instance.