DEV Community

Cover image for Connect GCP Compute Engine Via SSH Termius
Rusydy
Rusydy

Posted on

Connect GCP Compute Engine Via SSH Termius

To connect to a Google Cloud Platform (GCP) Compute Engine instance using SSH and Termius, you will need to follow these steps:

Steps to Generate and Register SSH Key

Generate an SSH key pair on your local machine.



ssh-keygen -t rsa -f ~/.ssh/KEY_FILENAME -C USERNAME -b 2048


Enter fullscreen mode Exit fullscreen mode
  • KEY_FILENAME: This is the name of the SSH key pair. You can use any name you want, but it is recommended that you use a name that is unique to the Compute Engine instance you are connecting to.

  • USERNAME: This is the username you want to use to log in to the Compute Engine instance.

  • The default location for the SSH key pair is ~/.ssh. If you would like to change the location, you can use the -d option.

  • The default size for the SSH key pair is 2048 bits. If you would like to change the size, you can use the -b option.

Register your Public Key to Compute Engine Instance

  1. Copy the public key to the clipboard by running the following command:


cat ~/.ssh/id_rsa.pub


Enter fullscreen mode Exit fullscreen mode
  1. Navigate to the "Metadata" section of the Compute Engine instance in the GCP Console.
  2. Click the "Edit" button.
  3. Click the "SSH Keys" tab.
  4. Click the "Add Item" button.
  5. Paste the public key into the "Key" field.
  6. Click the "Save" button.

Add public key

Steps to Connect to Compute Engine Instance

  1. Open Termius on your local machine.
  2. In the Termius dashboard, click the "Add Host" button.
  3. In the "Add Host" window, enter the following information:

    Add Host

    • Address: This should be the external IP address of your Compute Engine instance. You can find the external IP address in the GCP Console by navigating to the "Networking" section and clicking on the "External IP addresses" tab.
    • Port: The default SSH port is 22, so you can leave this field set to 22 unless you have changed the default port for your instance.
    • Username: This should be the username you want to use to log in to the Compute Engine instance.
    • Set a Key: Use the private key from ssh key we generated previously.
  4. Click the "Save" button in the "Add Host" window.

  5. Click the "Connect" button next to the host you just created.

  6. You should now be connected to the Compute Engine instance.

Note: If you are having trouble connecting to your Compute Engine instance, make sure that the firewall rules for the instance allow incoming connections on port 22 (the default SSH port) and that the instance has a public IP address. You can also check the logs for the instance in the GCP Console to see if there are any error messages that can help troubleshoot the issue.

Top comments (1)

Collapse
 
angelcosta profile image
Angélica Costa

Don't you have to add this newly created ssh key to the instance by editing it?