Generating SSH Keys

Last Updated : Dec 05, 2021 |

Procedure

  1. Generate SSH keypair for use with Google Compute Engine using the following command:
    # ssh-keygen -t rsa -f ~/.ssh/google_compute_engine
  2. In the Google Developers Console, click Computer  > Compute Engine > Metadata > SSH Keys > Edit.
  3. Enter the output generated from ~/.ssh/google_compute_engine.pub file, and click Save.
  4. To enable SSH agent to use this identity file for each new local console session, run the following command on the console:
    # ssh-add ~/.ssh/google_compute_engine
  5. To automate the command, add the below line to your ~/.ssh/config file.
    IdentityFile ~/.ssh/google_compute_engine
  6. You can now connect via standard SSH to the new VM instances created in your Google Compute Engine project.
    # ssh -i ~/.ssh/google_compute_engine  <username>@<instance_external_ip>