Search code examples
linuxscp

SCP not working permission denied even with SSH key given


I am trying to get scp to work and transfer a file from a remote server to my local. I tried looking around and this post helped the most but it still is not working here is the current output.

<HOSTNAME>:chef4-rep
<USERNAME>$ sudo scp -i ./.chef/<NAME>.pem <USERNAME>@<IP>:/home/postgres/post_0604_dump/db0604_schema_and_data.sql ~/
<USERNAME>@<IP>: Permission denied (publickey).

Solution

  • The issue turned out not to be with my command but that I was trying to copy a file in another users directory and it wouldn't work. I ended up SSH'ing in and using sudo to copy the file to my home directory and then used scp with no issues.