简体   繁体   中英

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).

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.

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

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@??.??.??.???:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM