gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 20:01:10 25 4
gpt4 key购买 nike

我已经阅读了几篇关于这个问题的 StackOverflow 文章,并在没有运气的情况下搜索了其他来源。我检查了 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似乎甚至没有尝试使用指定的身份文件。我得到以下输出:
    (注意正在执行的程序已经从 -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
    但是,当我运行 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 因将破折号和引号更改为排版版本而臭名昭著。这是需要小心的事情。

    关于macos - 使用 scp 将文件从 Mac OS 复制到 Amazon EC2 实例时出现权限被拒绝错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29508104/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com