我已经阅读了几篇有关这个问题的StackOverflow文章并在其他来源上进行了谷歌搜索,但没有任何收获。我已经检查了AWS文档,但无法解决问题。我已经花费了几个小时来处理这个问题,但卡住了。
我发现有些文章提到了类似的问题,但问题似乎总是由用户的拼写错误或操作失误引起的。在我的情况下,我确信我已经确保我所做的一切都没有拼写错误或错误。
我使用Mac OS X Yosemite连接到我的AWS EC2实例。我无法将文件从本地机器传输到我的实例中,但我过去曾经能够这样做,我相信是在升级到Yosemite之前(尽管我不确定是在升级之前还是之后)。无论如何,我现在遇到了权限被拒绝的错误。
我能够通过
我遇到了以下错误:
"Permission denied (publickey). lost connection"
我已经尝试了数小时并确认了以下内容:
1. 我可以正常使用ssh命令。 2. 我的.pem文件权限为400,且不对外公开。 3. 我在/var/www和/var/www/html文件夹中拥有正确的权限和所有权。(我重新按照Amazon的设置教程进行操作,确保我使用了他们描述的所有权限设置。我的用户是具有访问这些文件夹权限的组的一部分。)
当我运行scp -v命令时,我可以看到scp似乎甚至没有尝试使用指定的身份验证文件。我得到以下输出:
(请注意,执行的程序从scp命令中删除了-i)
我不确定还有什么其他尝试方法,也不知道如何解决这个问题。我希望有人能够确认这个问题或提供解决方案,特别是在同样的环境下。
谢谢!
我发现有些文章提到了类似的问题,但问题似乎总是由用户的拼写错误或操作失误引起的。在我的情况下,我确信我已经确保我所做的一切都没有拼写错误或错误。
我使用Mac OS X Yosemite连接到我的AWS EC2实例。我无法将文件从本地机器传输到我的实例中,但我过去曾经能够这样做,我相信是在升级到Yosemite之前(尽管我不确定是在升级之前还是之后)。无论如何,我现在遇到了权限被拒绝的错误。
我能够通过
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"
我已经尝试了数小时并确认了以下内容:
1. 我可以正常使用ssh命令。 2. 我的.pem文件权限为400,且不对外公开。 3. 我在/var/www和/var/www/html文件夹中拥有正确的权限和所有权。(我重新按照Amazon的设置教程进行操作,确保我使用了他们描述的所有权限设置。我的用户是具有访问这些文件夹权限的组的一部分。)
当我运行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”选项传递给ssh。你能否重试产生第一个调试跟踪的scp命令,并确保指定了-i选项?并在调试跟踪中包含实际的scp命令? - Kensterscp —i mykey.pem...
中的“—i”不是ASCII短横线。它是一些Unicode破折号字符。当我将该行复制/粘贴到终端窗口时,scp并不将其解释为-i选项。执行命令时,请确保键入ASCII短横线。 - Kenster