简体   繁体   English

使用Putty中的scp命令将文件夹/文件从本地计算机复制到AWS ec2实例时,权限被拒绝的公共密钥

[英]permission denied public key while copying folder/file from local machine to AWS ec2 instance with scp command in putty

i have an EC2 instance running ubuntu and i am connected to this instance using putty. 我有一个运行ubuntu的EC2实例,并且我使用腻子连接到了该实例。 i am trying to upload some files to this instance but getting permission denied public key error again and again. 我正在尝试将一些文件上传到此实例,但是一次又一次地获得许可被拒绝的公共密钥错误。 below are the commands i tried but received same error. 以下是我尝试过但收到相同错误的命令。

    login as: ubuntu
    Authenticating with public key "imported-openssh-key"
    Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-44-generic x86_64)

    * Documentation:  https://help.ubuntu.com/

    System information as of Wed Mar 25 05:21:29 UTC 2015

    System load:  0.0                Processes:           147
    Usage of /:   11.8% of 15.61GB   Users logged in:     1
    Memory usage: 47%                IP address for eth0: 172.31.24.22
    Swap usage:   0%
    ubuntu@ip-172-31-24-22:/var/www/html$ scp -r     \xampp\htdocs\bucketsorter\index.php ubuntu@ip-172-31-24-22:home/ubuntu/var
    Permission denied (publickey).
    lost connection
    ubuntu@ip-172-31-24-22:/var/www/html$ scp -r -v \xampp\htdocs\bucketsorter\index.php ubuntu@ip-172-31-24-22:home/ubuntu/var
    Executing: program /usr/bin/ssh host ip-172-31-24-22, user ubuntu,   command scp -v -r -t home/ubuntu/var
    OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
    debug1: Reading configuration data /etc/ssh/ssh_config
    debug1: /etc/ssh/ssh_config line 19: Applying options for *
    debug1: Connecting to ip-172-31-24-22 [172.31.24.22] port 22.
    debug1: Connection established.
    debug1: identity file /home/ubuntu/.ssh/id_rsa type -1
    debug1: identity file /home/ubuntu/.ssh/id_rsa-cert type -1
    debug1: identity file /home/ubuntu/.ssh/id_dsa type -1
    debug1: identity file /home/ubuntu/.ssh/id_dsa-cert type -1
    debug1: identity file /home/ubuntu/.ssh/id_ecdsa type -1
    debug1: identity file /home/ubuntu/.ssh/id_ecdsa-cert type -1
    debug1: identity file /home/ubuntu/.ssh/id_ed25519 type -1
    debug1: identity file /home/ubuntu/.ssh/id_ed25519-cert type -1
    debug1: Enabling compatibility mode for protocol 2.0
    debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
    debug1: Remote protocol version 2.0, remote software version     OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
    debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2 pat OpenSSH_6.6.1* compat  0x04000000
    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: sending SSH2_MSG_KEX_ECDH_INIT
    debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
    debug1: Server host key: ECDSA     e9:2c:36:dd:be:72:1e:8a:cd:4d:1d:71:be:38:51:20
    debug1: Host 'ip-172-31-24-22' is known and matches the ECDSA host key.
    debug1: Found key in /home/ubuntu/.ssh/known_hosts:2
    debug1: ssh_ecdsa_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: /home/ubuntu/.ssh/id_rsa
    debug1: Trying private key: /home/ubuntu/.ssh/id_dsa
    debug1: Trying private key: /home/ubuntu/.ssh/id_ecdsa
    debug1: Trying private key: /home/ubuntu/.ssh/id_ed25519
    debug1: No more authentication methods to try.
    Permission denied (publickey).
    lost connection
    ubuntu@ip-172-31-24-22:/var/www/html$ scp -r -v -i \Users\Rohan\Desktop\fall2014 courses\research\bucketsort-aws.pem \xampp\htdocs\bucketsorter\index.php ubuntu@ip-172-31-24-22:home/ubuntu/var
    Executing: program /usr/bin/ssh host ip-172-31-24-22, user ubuntu,   command scp -v -r -d -t home/ubuntu/var
    Warning: Identity file UsersRohanDesktopfall2014 not accessible: No such file or directory.
    OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
    debug1: Reading configuration data /etc/ssh/ssh_config
    debug1: /etc/ssh/ssh_config line 19: Applying options for *
    debug1: Connecting to ip-172-31-24-22 [172.31.24.22] port 22.
    debug1: Connection established.
    debug1: identity file /home/ubuntu/.ssh/id_rsa type -1
    debug1: identity file /home/ubuntu/.ssh/id_rsa-cert type -1
    debug1: identity file /home/ubuntu/.ssh/id_dsa type -1
    debug1: identity file /home/ubuntu/.ssh/id_dsa-cert type -1
    debug1: identity file /home/ubuntu/.ssh/id_ecdsa type -1
    debug1: identity file /home/ubuntu/.ssh/id_ecdsa-cert type -1
    debug1: identity file /home/ubuntu/.ssh/id_ed25519 type -1
    debug1: identity file /home/ubuntu/.ssh/id_ed25519-cert type -1
    debug1: Enabling compatibility mode for protocol 2.0
    debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
    debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
    debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2 pat OpenSSH_6.6.1* compat 0x04000000
    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: sending SSH2_MSG_KEX_ECDH_INIT
    debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
    debug1: Server host key: ECDSA e9:2c:36:dd:be:72:1e:8a:cd:4d:1d:71:be:38:51:20
    debug1: Host 'ip-172-31-24-22' is known and matches the ECDSA host key.
    debug1: Found key in /home/ubuntu/.ssh/known_hosts:2
    debug1: ssh_ecdsa_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: /home/ubuntu/.ssh/id_rsa
    debug1: Trying private key: /home/ubuntu/.ssh/id_dsa
    debug1: Trying private key: /home/ubuntu/.ssh/id_ecdsa
    debug1: Trying private key: /home/ubuntu/.ssh/id_ed25519
    debug1: No more authentication methods to try.
    Permission denied (publickey).
    lost connection
    ubuntu@ip-172-31-24-22:/var/www/html$

I have tried with root as a user as well. 我也以root用户身份尝试过。 I have been trying to figure it out since 6 hours and now really frustrated. 自6个小时以来,我一直在努力弄清楚,现在真的很沮丧。 i am newbie in linux. 我是linux的新手。 please help me solve this. 请帮我解决这个问题。 thanks in advance 提前致谢

In the sample terminal output, your first two scp attempts never even tried to authenticate. 在示例终端输出中,您的前两次scp尝试甚至从未尝试进行身份验证。 The remote system only accepts public key authentication (not passwords), and ssh didn't have any public keys to authenticate with. 远程系统仅接受公共密钥身份验证(不接受密码),并且ssh没有任何可用于身份验证的公共密钥。

In your third scp attempt, there is this: 在您的第三次scp尝试中,有以下内容:

$ scp -r -v -i \Users\Rohan\Desktop\fall2014 courses\research\bucketsort-aws.pem \xampp\htdocs\bucketsorter\index.php ubuntu@ip-172-31-24-22:home/ubuntu/var
Executing: [...]
Warning: Identity file UsersRohanDesktopfall2014 not accessible: No such file or directory.

You told it to use the key file "\\Users\\Rohan\\Desktop\\fall2014 courses\\research\\bucketsort-aws.pem" without quotes. 您告诉它使用没有引号的密钥文件“ \\ Users \\ Rohan \\ Desktop \\ fall2014 course \\ research \\ bucketsort-aws.pem”。 Scp ended up looking for a key file named "UsersRohanDesktopfall2014". Scp最终寻找了一个名为“ UsersRohanDesktopfall2014”的密钥文件。 It couldn't find this key, so once again it couldn't authenticate. 它找不到此密钥,因此再次无法认证。

First of all, the name of your keyfile contains a space, so it must be surrounded with quotes to be seen as a single command-line parameter. 首先,密钥文件的名称包含一个空格,因此必须将其用引号引起来,才能将其视为单个命令行参数。 Second, it looks like backslashes on the command line are being mangled, so try using forward slashes instead: 其次,看起来命令行上的反斜杠已被修饰,因此请尝试使用正斜杠代替:

$ scp -r -v -i "/Users/.../fall2014 courses/research/bucketsort-aws.pem" /xampp/.../index.php ubuntu@ip-172-31-24-22:home/ubuntu/var

This is on Windows? 这是在Windows上吗? If scp still complains about not being able to find the key file, add the drive specifier: 如果scp仍然抱怨无法找到密钥文件,请添加驱动器说明符:

$ scp -r -v -i "C:/Users/.../fall2014 courses/research/bucketsort-aws.pem" /xampp/.../index.php ubuntu@ip-172-31-24-22:home/ubuntu/var
$ scp -r -v -i \Users\Rohan\Desktop\fall2014 courses\research\bucketsort-aws.pem \xampp\htdocs\bucketsorter\index.php ubuntu@ip-172-31-24-22:home/ubuntu/var

Why are you using Backslash in above command? 为什么在上述命令中使用反斜杠 what exactly are you doing? 你到底在做什么

Also, if you want to copy files from Local windows workstation to remote EC2 Linux box, Use something like FileZilla, WinSCP OR BitWise. 另外,如果要将文件从本地Windows工作站复制到远程EC2 Linux框中,请使用FileZilla,WinSCP或BitWise之类的文件。

PuTTy Can NOT transfer files. PuTTy无法传输文件。

Besides, ubuntu@ip-172-31-24-22:home/ubuntu/var should be ubuntu@ip-172-31-24-22:/home/ubuntu/var (Notice a / before home ) 此外, ubuntu@ip-172-31-24-22:home/ubuntu/var应该是ubuntu@ip-172-31-24-22:/home/ubuntu/var (注意/ home之前)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM