0

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).
  • 1
    did you copy your public key to the remote ~./ssh/authorized_keys ? – physi Jun 06 '18 at 12:48
  • And are the permissions on your private key and its containing directory correct? Can you use the same key and connect manually? – ivanivan Jun 06 '18 at 12:54
  • @ivanivan That is what I ended up doing before I saw your comment. I posted an answer to the thread. –  Jun 06 '18 at 13:03
  • Does this answer your question? [Copy file via scp](https://stackoverflow.com/questions/18509457/copy-file-via-scp) – Mertuarez Apr 26 '20 at 18:55

3 Answers3

1

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.

0

Kindly use below command to get it done.

root@localhost# scp -r "source_file/directory" "Destination address- remote-IP/Hostname:/location"

And if you are using passwordless ssh then make sure you are using correct user whose public keys are shared with remote server.

Thanks

Mayank C Koli
  • 21
  • 1
  • 3
  • 1
    I resolved the issue, I just posted it as you sent yours. It was a permissions issue that I could not access the file remotely so I had to move it, my command was correct. The -r flag is redundant because I was just transferring a single file not a directory. –  Jun 06 '18 at 13:02
-1

I had the same issue with scp and got Permission denied (publickey):

This worked: ssh -i "mykey.pem" ubuntu@??.??.??.???

But this didn't: scp -i "mykey.pem" test.php ubuntu@??.??.??.???:

I solved it by removing the quotes off my key file:

scp -i mykey.pem test.php ubuntu@??.??.??.???:

Digvijay S
  • 2,665
  • 1
  • 9
  • 21