1

I have two linux instances in gcp and both are in the same project i created a demo.txt file in instance-1 and i want to transfer this file from instance-1 to instance-2, so i came up with this command

scp -i ~/.ssh/my-ssh-key [USERNAME]@[IP_ADDRESS]:[REMOTE_FILE_PATH] [LOCAL_FILE_PATH]

i also created a key using this command in instance-1

ssh-keygen -t rsa -f ~/.ssh/[ssh-key] -C [root]

my ssh-key is located in /root/.ssh it have two file '[ssh-key]' and '[ssh-key].pub' and i use exactly this command to share file

scp -i ~/.ssh/'[ssh-key].pub' [root]@[externalIP_of_instance-2]:/usr/ /usr/demo.txt

but getting this error.

external_ip_of_instance-2: Permission denied (publickey)

what am i doing wrong?

Thanks

1 Answer 1

0

You need to add your [ssh-key].pub key of the machine you are connecting from to authorized keys on machine you are connecting to. The location of this file is:

~/.ssh/authorized_keys

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .