为什么在SSH工作时为SCP取得权限被拒绝(公钥)错误?

我正试图使用​​SCP将本地主机上的文件复制到Amazon EC2实例,并收到错误消息:

警告:身份文件blocks_key.pem不可访问:没有这样的文件或目录。 权限被拒绝(publickey)。 失去了连接

提示此错误的命令是:

scp -i ~/Desktop/Blocks/blocks_key.pem ~/Desktop/Blocks/code/www/uploadtest.html [email protected]:/var/www 

我能够SSH使用相同的-i〜/ Desktop / Blocks / blocks_key.pem,所以我不清楚为什么这不能正常工作。 任何有识之士将不胜感激!

debugging信息:

 OpenSSH_5.3p1 Debian-3ubuntu7, OpenSSL 0.9.8k 25 Mar 2009 Warning: Identity file /Desktop/Blocks/blocks_key.pem not accessible: No such file or directory. debug1: Reading configuration data /etc/ssh/ssh_config debug1: Applying options for * debug1: Connecting to 184.73.234.234 [184.73.234.234] port 22. debug1: Connection established. debug1: identity file /home/ubuntu/.ssh/identity type -1 debug1: identity file /home/ubuntu/.ssh/id_rsa type -1 debug1: identity file /home/ubuntu/.ssh/id_dsa type -1 debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3p1 Debian-3ubuntu7 debug1: match: OpenSSH_5.3p1 Debian-3ubuntu7 pat OpenSSH* debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_5.3p1 Debian-3ubuntu7 debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: server->client aes128-ctr hmac-md5 none debug1: kex: client->server aes128-ctr hmac-md5 none debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP debug1: SSH2_MSG_KEX_DH_GEX_INIT sent debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY debug1: Host '184.73.234.234' is known and matches the RSA host key. debug1: Found key in /home/ubuntu/.ssh/known_hosts:1 debug1: ssh_rsa_verify: signature correct debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: SSH2_MSG_SERVICE_REQUEST sent debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey debug1: Next authentication method: publickey debug1: Trying private key: /home/ubuntu/.ssh/identity debug1: Trying private key: /home/ubuntu/.ssh/id_rsa debug1: Trying private key: /home/ubuntu/.ssh/id_dsa debug1: No more authentication methods to try. Permission denied (publickey). lost connection 

谢谢

也许你发现了一个错误?

做同样的事情的另一种方式(不知道这是否适合你?):

scp -oIdentityFile=/Users/emmie/Desktop/Blocks/blocks_key.pem ~/Desktop/Blocks/code/www/uploadtest.html [email protected]:/var/www

此外,它可能会帮助(只是好奇),如果你发布的输出:

stat /Users/emmie/Desktop/Blocks/blocks_key.pem

从你的详细输出看到这个消息。

 Warning: Identity file /Desktop/Blocks/blocks_key.pem not accessible: No such file or directory. 

而不是使用~/ ,尝试在命令行中提供完整的path。 也许你正在使用一个不支持~扩展到你的主目录的shell。

不知道这是否是你的问题,但是你会给出一个scp的path,它实际上允许它find文件系统上的密钥,以便使用它。

如果您使用的是Amazon Web服务,您只需要通过返回到putty并保存IP和path来重新连接ec2,然后加载ip。 terminal将打开,让你连接到ec2。 它为我工作。

祝你好运

确保/ var / www的权限设置正确(chmod 777 / var / www应该可以)