This guide will walk you through the steps to connect two Google Cloud instances (referred to as the Host and the Guest) using SSH (a method for securely connecting to another computer). Don’t worry if you’re unfamiliar with SSH—each step is explained in easy-to-understand language.
Before we start, make sure:
- You have access to two Google Cloud instances: one will be the Host and the other will be the Guest.
- You can log in to both instances (using Google Cloud's SSH button is a simple way to do this).
We need to adjust the settings of the Guest instance so that it allows root login and password authentication.
- Log in to your Guest instance.
- In Google Cloud, go to your Guest instance and click the SSH button to open a terminal window.
- Once you are logged in, enter the following command to open the SSH configuration file:
sudo nano /etc/ssh/sshd_config
- Inside the file, look for these two lines:
PermitRootLogin
PasswordAuthentication
- Change both of these to
yes
(if they are not already set toyes
). - After making these changes, save the file and close it (press CTRL+X, then Y, and hit Enter to save).
- Now restart the SSH service by running this command:
sudo systemctl restart sshd
Now, we'll connect from the Host instance to the Guest instance using its IP address.
- Log in to your Host instance.
- In Google Cloud, go to your Host instance and click the SSH button.
- To connect to the Guest instance, run the following command, replacing
Guest_IP
with the actual IP address of your Guest instance:ssh root@Guest_IP
- If prompted, enter the Guest instance's root password (the default password for root access).
This optional step will allow you to connect to the Guest instance from the Host without entering a password each time.
- On the Host instance, generate an SSH key by running this command:
ssh-keygen -t rsa
- When prompted to choose a file location, you can just press Enter to use the default location.
- After the key is generated, copy it to the Guest instance with this command:
ssh-copy-id root@Guest_IP
- Replace
Guest_IP
with the actual IP address of your Guest instance. - When prompted, enter the Guest root password one last time.
- Replace
Now, you will be able to connect from the Host to the Guest without needing to enter a password every time!
For security reasons, you might want to change the root password on the Guest instance.
- Log in to your Guest instance (either through Google Cloud or using the SSH command).
- To change the root password, enter the following command:
sudo passwd root
- Follow the prompts to enter a new password and confirm it.
That's it! You’ve successfully set up a connection between two Google Cloud instances using SSH. If you followed the optional steps, you also made it more convenient and secure by setting up password-free login.