尝试使用 scp 复制文件时出错

尝试使用 scp 复制文件时出错

我正在连接到 Ubuntu 实例,运行一些 Apache/JMeter 测试,并且尝试使用 scp 从所述测试中获取日志文件。

我使用以下命令连接:

ssh my-host.amazonaws.com -l my-username

我可以连接,也可以运行测试。但是,我还没有执行过 scp 命令而不出现错误。

我正在使用以下命令:

scp [email protected]:~/my-file-name.jtl ./

我立即收到以下错误:

Permission denied (publickey).

知道问题可能出在哪里吗?首先,我有权限连接到该机器。此外,“my-username”用户名由几个测试用户共享,其他人可以毫无问题地执行 scp 命令。

编辑:这是我尝试使用 -v 参数的 scp 命令的输出:

my-username@ip-xx-xx-xxx-xx:~$ scp -v 
    [email protected]:/home/ubuntu/jmeter.log ./
Executing: program /usr/bin/ssh host my-host.amazonaws.com, 
    user ubuntu, command scp -v -f /home/ubuntu/jmeter.log
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 my-host.amazonaws.com [xx.xx.xxx.xx] 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.8
debug1: Remote protocol version 2.0, remote software version 
    OpenSSH_6.6.1p1     Ubuntu-2ubuntu2.8
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8 pat OpenSSH_6.6.1* 
    compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr [email protected] none
debug1: kex: client->server aes128-ctr [email protected] none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA     xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
debug1: Host 'my-host.amazonaws.com' is known and matches the ECDSA host
    key.
debug1: Found key in /home/ubuntu/.ssh/known_hosts:1
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
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_xxx
debug1: Trying private key: /home/ubuntu/.ssh/id_yyy
debug1: Trying private key: /home/ubuntu/.ssh/id_abcde
debug1: Trying private key: /home/ubuntu/.ssh/id_zzzzzzz
debug1: No more authentication methods to try.
Permission denied (publickey).

以下是我最初的 SSH 连接的详细日志记录:

$ ssh -v my-host.amazonaws.com -l ubuntu
OpenSSH_6.6.1, OpenSSL 1.0.1i 6 Aug 2014
debug1: Reading configuration data /c/Users/jdoe/.ssh/config
debug1: Connecting to my-host.amazonaws.com [xx.xxx.xxx.xxx] port 22.
debug1: Connection established.
debug1: identity file /c/Users/jdoe/.ssh/id_rsa type 1
debug1: identity file /c/Users/jdoe/.ssh/id_rsa-cert type -1
debug1: identity file /c/Users/jdoe/.ssh/id_dsa type -1
debug1: identity file /c/Users/jdoe/.ssh/id_dsa-cert type -1
debug1: identity file /c/Users/jdoe/.ssh/id_ecdsa type -1
debug1: identity file /c/Users/jdoe/.ssh/id_ecdsa-cert type -1
debug1: identity file /c/Users/jdoe/.ssh/id_ed25519 type -1
debug1: identity file /c/Users/jdoe/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1         
    Ubuntu-2ubuntu2.8
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8 pat OpenSSH_6.6.1* compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr [email protected] none
debug1: kex: client->server aes128-ctr [email protected] none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA     xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
debug1: Host 'my-host.amazonaws.com' is known and matches the ECDSA host key.
debug1: Found key in /c/Users/jdoe/.ssh/known_hosts:10
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: Offering RSA public key: /c/Users/jdoe/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
Authenticated to my-host.amazonaws.com ([xx.xxx.xxx.xxx]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 3.13.0-95-generic x86_64)

答案1

您不是从同一台机器或从同一用户运行这两个命令。

一个输出说 /home/ubuntu/.ssh/id_rsa 被使用,另一个输出说 /c/Users/jdoe/.ssh/id_rsa

因此,您可能在 scp 案例中使用了错误的密钥,来自错误的目录。

相关内容