简体   繁体   English

即使给定了 SSH 密钥,SCP 也无法工作权限被拒绝

[英]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.我试图让scp工作并将文件从远程服务器传输到我的本地。 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.我最终通过 SSH 进入并使用sudo将文件复制到我的主目录,然后使用scp没有问题。

Kindly use below command to get it done.请使用以下命令来完成它。

root@localhost# scp -r "source_file/directory" "Destination address- remote-IP/Hostname:/location" root@localhost# scp -r "source_file/directory" "目标地址-远程 IP/主机名:/位置"

And if you are using passwordless ssh then make sure you are using correct user whose public keys are shared with remote server.如果您使用的是无密码 ssh,请确保您使用的是正确的用户,其公钥与远程服务器共享。

Thanks谢谢

I had the same issue with scp and got Permission denied (publickey) :我在 scp 上遇到了同样的问题,并获得了Permission denied (publickey)

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

But this didn't: scp -i "mykey.pem" test.php ubuntu@??.??.??.???:但这没有: 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@??.??.??.???:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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