权限被拒绝使用scp将文件从Mac OS复制到Amazon EC2实例时出错

Ste*_*e K 5 macos scp amazon-ec2 permission-denied amazon-web-services

我已经阅读了几篇有关此问题的StackOverflow文章,并搜索其他来源,但没有运气.我检查过AWS文档但无法解决问题.我已经在这工作了几个小时,我真的被卡住了.

我发现文章提到了类似的问题,但问题看起来总是在用户方面犯了错字或错误.在我的情况下,我相信我已经确保我正在做的事情没有错别字或错误.

我正在使用Mac OS X Yosemite连接到我的AWS EC2实例.我不能scp从我的本地机器到我的实例的文件,但我能够在过去,我相信在升级到Yosemite之前(尽管我在升级之前或之后不是100%肯定).无论如何,我现在收到一个拒绝权限错误.

我能够ssh很好地进入我的实例.我这样做:

ssh -i mykey.pem ec2-user@myEC2host.myzone.compute.amazonaws.com
Run Code Online (Sandbox Code Playgroud)

一切正常ssh.但是当我尝试scp这样的时候:

scp —i mykey.pem ~/Sites/test.html ec2-user@myEC2host.myzone.compute.amazonaws.com:/var/www/html/
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

权限被拒绝(publickey).失去了连接

我已经尝试了几个小时,并确认了以下内容:

  1. 我ssh可以很好.
  2. 我的.pem文件具有400权限,无法向全世界查看.
  3. 我在/var/www和/var/www/html文件夹中拥有正确的权限和所有权

    (我再次浏览了亚马逊设置教程并确保我按照他们的描述使用了所有权限设置.我的用户是可以访问这些文件夹的组的一部分.

当我运行scp -v命令时,我可以看到scp甚至没有尝试使用指定的身份文件.我得到以下输出:

(注意正在执行的程序-i已从scp命令中删除)

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
Run Code Online (Sandbox Code Playgroud)

但是,当我运行时,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
Run Code Online (Sandbox Code Playgroud)

我不知道还有什么可以尝试,或者我怎么能解决这个问题.我希望有人会有相同的环境,可以确认问题或提供解决方案.

提前致谢!

Ken*_*ter 4

scp \xe2\x80\x94i mykey.pem ~/Sites/test.html ec2-user@myEC2host.myzone.compute.amazonaws.com:/var/www/html/\nExecuting: program /usr/bin/ssh host myEC2host.myzone.compute.amazonaws.com, user ec2-user, command scp -v -d -t /var/www/html/\n
Run Code Online (Sandbox Code Playgroud)\n\n

命令中的破折号scp \xe2\x80\x94i...是 unicode EM 破折号,而不是 ASCII 破折号。scp 不会将其解释为命令行选项。

\n\n

事实上,它将“\xe2\x80\x94i”、“mykey.pem”和“~/Sites/test.html”解释为要复制的三个文件。您可以看出这一点,因为 scp 在远程 scp 实例的命令行中添加了“-d”。“-d”标志告诉远程 scp 实例目标必须是一个目录。scp 在复制多个文件时会将该标志添加到远程命令中,但在复制单个文件时则不会。

\n\n

也许您从文字处理文档中复制了 scp 命令?Microsoft Word 因将破折号和引号更改为排版版本而臭名昭著。这是需要小心的事情。

\n