使用 scp 将文件从 Mac OS 复制到 Amazon EC2 实例时出现权限被拒绝错误
Permission Denied Error when using scp to copy a file to Amazon EC2 instance from Mac OS
我已经阅读了几篇关于这个问题的 Whosebug 文章,并在谷歌上搜索了其他资源,但没有成功。我检查了 AWS 文档,但无法解决问题。我已经为此工作了几个小时,但真的卡住了。
我找到了提到类似问题的文章,但问题看起来总是用户方面的拼写错误或错误。就我而言,我有信心确保我所做的事情没有错别字或错误。
我正在使用 Mac OS X Yosemite 连接到我的 AWS EC2 实例。我不能从我的本地机器 scp
文件到我的实例,但我过去可以,我相信在我升级到 Yosemite 之前(虽然我不是 100% 确定之前或之后升级)。无论如何,我现在收到权限被拒绝的错误。
我能够 ssh
很好地进入我的实例。我这样做:
ssh -i mykey.pem ec2-user@myEC2host.myzone.compute.amazonaws.com
ssh
一切正常。但是当我这样尝试 scp
时:
scp —i mykey.pem ~/Sites/test.html ec2-user@myEC2host.myzone.compute.amazonaws.com:/var/www/html/
我收到以下错误:
Permission denied (publickey). lost connection
我已经尝试了几个小时并确认了以下内容:
我可以 ssh
就好了。
我的 .pem
文件具有 400
权限并且
对世界不可见。
我在 /var/www
和 /var/www/html
文件夹中拥有正确的权限和所有权
(我再次阅读了亚马逊设置教程并确保我使用了他们描述的所有权限设置。我的用户是有权访问这些文件夹的组的一部分。
当我 运行 scp -v
命令时,我可以看到 scp
似乎甚至没有尝试使用指定的标识文件。我得到以下输出:
(注意正在执行的程序已经从 scp
命令中删除了 -i
)
Executing: program /usr/bin/ssh host myEC2host.myzone.compute.amazonaws.com, user ec2-user, command scp -v -d -t /var/www/html/
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to myEC2host.myzone.compute.amazonaws.com [public AWS ip] port 22.
debug1: Connection established.
debug1: identity file /Users/myusername/.ssh/id_rsa type -1
debug1: identity file /Users/myusername/.ssh/id_rsa-cert type -1
debug1: identity file /Users/myusername/.ssh/id_dsa type -1
debug1: identity file /Users/myusername/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.2
debug1: match: OpenSSH_6.2 pat OpenSSH*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com 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: Server host key: RSA {some hex output}
debug1: Host 'myEC2host.myzone.compute.amazonaws.com' is known and matches the RSA host key.
debug1: Found key in /Users/myusername/.ssh/known_hosts:2
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
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: /Users/myusername/.ssh/id_rsa
debug1: Trying private key: /Users/myusername/.ssh/id_dsa
debug1: No more authentication methods to try.
Permission denied (publickey).
lost connection
但是,当我 运行 ssh -v
时,我得到以下输出,它立即使用了正确的识别文件:
ssh -v -i mykey ec2-user@myEC2host.myzone.compute.amazonaws.com
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to myEC2host.myzone.compute.amazonaws.com [54.69.211.59] port 22.
debug1: Connection established.
debug1: identity file mykey.pem type -1
debug1: identity file mykey.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.2
debug1: match: OpenSSH_6.2 pat OpenSSH*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com 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: Server host key: RSA {some hex output}
debug1: Host 'myEC2host.myzone.compute.amazonaws.com' is known and matches the RSA host key.
debug1: Found key in /Users/myusername/.ssh/known_hosts:2
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
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: mike.pem
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
Authenticated to myEC2host.myzone.compute.amazonaws.com ([myEC2IP]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_CA.UTF-8
我不确定还可以尝试什么或如何解决这个问题。我希望有人拥有相同的环境并可以确认问题或提供解决方案。
提前致谢!
scp —i mykey.pem ~/Sites/test.html ec2-user@myEC2host.myzone.compute.amazonaws.com:/var/www/html/
Executing: program /usr/bin/ssh host myEC2host.myzone.compute.amazonaws.com, user ec2-user, command scp -v -d -t /var/www/html/
您的 scp —i...
命令中的破折号是 unicode EM 破折号,而不是 ASCII 破折号。 Scp 没有将其解释为命令行选项。
实际上它将“—i”、"mykey.pem"和“~/Sites/test.html”解释为要复制的三个文件。您可以看出这一点,因为 scp 在远程 scp 实例的命令行中添加了“-d”。 “-d”标志告诉远程 scp 实例目标必须是一个目录。当复制多个文件时,scp 会将该标志添加到远程命令,但不会复制单个文件。
也许您从文字处理文档中复制了 scp 命令? Microsoft Word 因将破折号和引号更改为排版版本而臭名昭著。这是一个需要注意的问题。
Kenster 正确地指出,我的代码中 -i
中的破折号实际上在我将其粘贴到终端之前已转换为 EMdash。 :-s
重新键入整个命令更正了问题。
感谢您发现我的疏忽。
我已经阅读了几篇关于这个问题的 Whosebug 文章,并在谷歌上搜索了其他资源,但没有成功。我检查了 AWS 文档,但无法解决问题。我已经为此工作了几个小时,但真的卡住了。
我找到了提到类似问题的文章,但问题看起来总是用户方面的拼写错误或错误。就我而言,我有信心确保我所做的事情没有错别字或错误。
我正在使用 Mac OS X Yosemite 连接到我的 AWS EC2 实例。我不能从我的本地机器 scp
文件到我的实例,但我过去可以,我相信在我升级到 Yosemite 之前(虽然我不是 100% 确定之前或之后升级)。无论如何,我现在收到权限被拒绝的错误。
我能够 ssh
很好地进入我的实例。我这样做:
ssh -i mykey.pem ec2-user@myEC2host.myzone.compute.amazonaws.com
ssh
一切正常。但是当我这样尝试 scp
时:
scp —i mykey.pem ~/Sites/test.html ec2-user@myEC2host.myzone.compute.amazonaws.com:/var/www/html/
我收到以下错误:
Permission denied (publickey). lost connection
我已经尝试了几个小时并确认了以下内容:
我可以
ssh
就好了。我的
.pem
文件具有400
权限并且 对世界不可见。我在
/var/www
和/var/www/html
文件夹中拥有正确的权限和所有权(我再次阅读了亚马逊设置教程并确保我使用了他们描述的所有权限设置。我的用户是有权访问这些文件夹的组的一部分。
当我 运行 scp -v
命令时,我可以看到 scp
似乎甚至没有尝试使用指定的标识文件。我得到以下输出:
(注意正在执行的程序已经从 scp
命令中删除了 -i
)
Executing: program /usr/bin/ssh host myEC2host.myzone.compute.amazonaws.com, user ec2-user, command scp -v -d -t /var/www/html/
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to myEC2host.myzone.compute.amazonaws.com [public AWS ip] port 22.
debug1: Connection established.
debug1: identity file /Users/myusername/.ssh/id_rsa type -1
debug1: identity file /Users/myusername/.ssh/id_rsa-cert type -1
debug1: identity file /Users/myusername/.ssh/id_dsa type -1
debug1: identity file /Users/myusername/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.2
debug1: match: OpenSSH_6.2 pat OpenSSH*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com 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: Server host key: RSA {some hex output}
debug1: Host 'myEC2host.myzone.compute.amazonaws.com' is known and matches the RSA host key.
debug1: Found key in /Users/myusername/.ssh/known_hosts:2
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
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: /Users/myusername/.ssh/id_rsa
debug1: Trying private key: /Users/myusername/.ssh/id_dsa
debug1: No more authentication methods to try.
Permission denied (publickey).
lost connection
但是,当我 运行 ssh -v
时,我得到以下输出,它立即使用了正确的识别文件:
ssh -v -i mykey ec2-user@myEC2host.myzone.compute.amazonaws.com
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to myEC2host.myzone.compute.amazonaws.com [54.69.211.59] port 22.
debug1: Connection established.
debug1: identity file mykey.pem type -1
debug1: identity file mykey.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.2
debug1: match: OpenSSH_6.2 pat OpenSSH*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com 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: Server host key: RSA {some hex output}
debug1: Host 'myEC2host.myzone.compute.amazonaws.com' is known and matches the RSA host key.
debug1: Found key in /Users/myusername/.ssh/known_hosts:2
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
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: mike.pem
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
Authenticated to myEC2host.myzone.compute.amazonaws.com ([myEC2IP]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_CA.UTF-8
我不确定还可以尝试什么或如何解决这个问题。我希望有人拥有相同的环境并可以确认问题或提供解决方案。
提前致谢!
scp —i mykey.pem ~/Sites/test.html ec2-user@myEC2host.myzone.compute.amazonaws.com:/var/www/html/
Executing: program /usr/bin/ssh host myEC2host.myzone.compute.amazonaws.com, user ec2-user, command scp -v -d -t /var/www/html/
您的 scp —i...
命令中的破折号是 unicode EM 破折号,而不是 ASCII 破折号。 Scp 没有将其解释为命令行选项。
实际上它将“—i”、"mykey.pem"和“~/Sites/test.html”解释为要复制的三个文件。您可以看出这一点,因为 scp 在远程 scp 实例的命令行中添加了“-d”。 “-d”标志告诉远程 scp 实例目标必须是一个目录。当复制多个文件时,scp 会将该标志添加到远程命令,但不会复制单个文件。
也许您从文字处理文档中复制了 scp 命令? Microsoft Word 因将破折号和引号更改为排版版本而臭名昭著。这是一个需要注意的问题。
Kenster 正确地指出,我的代码中 -i
中的破折号实际上在我将其粘贴到终端之前已转换为 EMdash。 :-s
重新键入整个命令更正了问题。
感谢您发现我的疏忽。