banner
davirain

davirain

twitter
github
知乎
twitter

How to remotely log in and access Google Cloud virtual machine instances using SSH on a local computer.

To remotely access a virtual machine instance on Google Cloud through SSH, you need to follow the following steps:

  1. Launch Google Cloud Shell

    Google Cloud Shell is a command-line tool built into the Google Cloud Console that provides full access to Google Cloud resources.

    You can start it by clicking the "Activate Cloud Shell" button in the top right corner (usually located on the right side of the top navigation bar). If this is your first time using Cloud Shell, a small virtual machine instance will be created for you.

  2. Create SSH Keys

    In Cloud Shell, you can run the following command to generate SSH key pairs:

    ssh-keygen -t rsa -f ~/.ssh/[KEY_FILENAME] -C [USERNAME]
    

    Replace [KEY_FILENAME] with your key file name and [USERNAME] with your username on the remote instance. When prompted, you can choose to enter a passphrase for the key pair or skip it.

    Note: By default, if you do not specify the key type (-t option) when running the ssh-keygen command, it will generate RSA keys.

  3. Add the Public Key to Google Cloud

    You need to add the public key you just generated to the "Metadata" page in Google Cloud. On the "Metadata" page, select the "SSH Keys" option, then click the "Edit" button, and finally click the "Add Item" button.

    You can use the cat command to view your public key:

    cat ~/.ssh/[KEY_FILENAME].pub
    

    Replace [KEY_FILENAME] with your key file name. Copy the displayed content and paste it into a new item on the "SSH Keys" page.

  4. Connect to the Remote Instance via SSH

    You can now connect to your Google Cloud VM instance using the following command:

    ssh -i ~/.ssh/[KEY_FILENAME] [USERNAME]@[IP_ADDRESS]
    

    Replace [KEY_FILENAME] with your key file name, [USERNAME] with your username on the remote instance, and [IP_ADDRESS] with the public IP address of your VM instance.

The above steps will help you connect to a virtual machine instance on Google Cloud through SSH. If you encounter any issues during the process, feel free to ask for further assistance.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.