I created a GCP instance, and I created a private and public key on kali linux, I saved this key in the metadata of GCP, so I can access the instance through my kali machine. Then, I need to copy a file from this GCP instance into my local machine, so Im using powershell command: scp -i C:\Users\mymachine\OneDrive\Desktop\ myprivatekey GCPUser@GCP_IP:/home/GCPUser/lastname.txt c:\Users\mymachine
But it gives me a publickey permission denied

  • Powershell didn't care about your public key: it's the server you're connecting to that does. It's, by the way, totally unclear why someone would use Kali, which is a special purpose non-development platform, for this kind of things, but I'm sure you have a good reason. Sep 1, 2023 at 23:24

1 Answer 1


Login to your GCP instance and run journalctl -ru ssh.service to see the most recent messages from sshd. The log message should include a reason why your public key authentication attempt was rejected.

The most common reason is that the ~/.ssh directory or the authorized_keys file in it is not protected well enough. If the permissions would allow other users to write into the ~/.ssh directory, sshd will ignore the authorized_keys file on the assumption that it might have been maliciously inserted by some other user.

If you are uncertain on how to change the permissions, please run namei -l ~/.ssh/authorized_keys and add the output into your original question post. It should display the permissions of the file, the directory it's in and all the parent directories at once.

A good result should be similar to this:

namei -l ~/.ssh/authorized_keys
f: /home/GCPUser/.ssh/authorized_keys
drwxr-xr-x root     root     /
drwxr-xr-x root     root     home
drwxr-xr-x GCPUser  GCPUser  GCPUser
drwx------ GCPUser  GCPUser  .ssh
-rw------- GCPUser  GCPUser  authorized_keys

You must log in to answer this question.

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