为什么 SSH 工作时会出现 SCP 权限被拒绝(公钥)错误

为什么 SSH 工作时会出现 SCP 权限被拒绝(公钥)错误

我正在尝试使用 SCP 将文件从本地主机复制到我的 Amazon EC2 实例并收到错误:

警告:身份文件 blocks_key.pem 无法访问:没有此文件或目录。权限被拒绝(公钥)。连接丢失

提示这个错误的命令是:

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

我能够使用相同的 -i ~/Desktop/Blocks/blocks_key.pem 进行 SSH,所以我不清楚为什么这不能正常工作。任何见解都将不胜感激!

调试信息:

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

谢谢

答案1

也许您发现了一个错误?

做同样事情的另一种方法(不知道这对您是否有用?):

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

答案2

从您的详细输出中查看此消息。

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

不要使用~/,尝试在命令行中提供完整路径。也许您使用的 shell 不支持将 扩展~到您的主目录。

不确定这是否是你的问题,但你将给 scp 一个路径,该路径实际上允许它在文件系统上找到密钥,以便使用它。

答案3

如果您使用的是 Amazon Web 服务,您需要做的就是返回 Putty 并保存 IP 和路径,然后加载 IP,以重新连接 EC2。终端将打开并允许您连接到 EC2。它对我有用。

祝你好运

答案4

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

相关内容