簡體   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

我有一個運行ubuntu的EC2實例,並且我使用膩子連接到了該實例。 我正在嘗試將一些文件上傳到此實例,但是一次又一次地獲得許可被拒絕的公共密鑰錯誤。 以下是我嘗試過但收到相同錯誤的命令。

    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$

我也以root用戶身份嘗試過。 自6個小時以來,我一直在努力弄清楚,現在真的很沮喪。 我是linux的新手。 請幫我解決這個問題。 提前致謝

在示例終端輸出中,您的前兩次scp嘗試甚至從未嘗試進行身份驗證。 遠程系統僅接受公共密鑰身份驗證(不接受密碼),並且ssh沒有任何可用於身份驗證的公共密鑰。

在您的第三次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.

您告訴它使用沒有引號的密鑰文件“ \\ Users \\ Rohan \\ Desktop \\ fall2014 course \\ research \\ bucketsort-aws.pem”。 Scp最終尋找了一個名為“ UsersRohanDesktopfall2014”的密鑰文件。 它找不到此密鑰,因此再次無法認證。

首先,密鑰文件的名稱包含一個空格,因此必須將其用引號引起來,才能將其視為單個命令行參數。 其次,看起來命令行上的反斜杠已被修飾,因此請嘗試使用正斜杠代替:

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

這是在Windows上嗎? 如果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

為什么在上述命令中使用反斜杠 你到底在做什么

另外,如果要將文件從本地Windows工作站復制到遠程EC2 Linux框中,請使用FileZilla,WinSCP或BitWise之類的文件。

PuTTy無法傳輸文件。

此外, 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