SSH from instance a to instance b

Hello i have a problem, i want to be able to connect to my second server with ssh from the first one: i explain myself : 

- i have instance wordpress

- i have a second instance database

- i add ssh-keys of my computer to metadata

so adding ssh-keys from my computer to metadata allow me to be able to connect to both server from my computer with ssh <ip_of_instance>.

But when i try to ssh <database_ip> from the server wordpress it says : "Permission denied".

I use gcp and terraform, so if you can tell me what could i had in my terraform to make it happen the way i want that would be great. Thanks a lot.

1 1 146
1 REPLY 1

Hello @Arout,

Welcome to Google Cloud Community!

Please make sure that you have set up SSH keys correctly for both instance A and instance B. SSH keys are used for authentication, and you need the public key on instance B and the private key on instance A.

  • On instance A: Check that the private key exists and has the correct permissions, 600 or 400 will do.

  • On instance B: Ensure that the corresponding public key is in the ~/.ssh/authorized_keys file. Create the file if it doesn't exist and have the correct permissions (600 or 644).