scp 错误:“权限被拒绝(公钥)。连接丢失”

scp 错误:“权限被拒绝(公钥)。连接丢失”

我尝试将 svn 转储 savannah,但最后出现了以下错误。

Permission denied (publickey).
lost connection

scp 命令和详细输出如下。有什么想法吗?

[wcyang@be2-wireless-pittnet-60-37 ~]$ scp -v diffcolor-dump.bz2 [email protected]:/srv/download/diffcolor/
Executing: program /usr/bin/ssh host dl.sv.gnu.org, user wcyang, command scp -v -t /srv/download/diffcolor/
OpenSSH_5.2p1, OpenSSL 0.9.7l 28 Sep 2006
debug1: Reading configuration data /etc/ssh_config
debug1: Connecting to dl.sv.gnu.org [140.186.70.73] port 22.
debug1: Connection established.
debug1: identity file /Users/wcyang/.ssh/identity type -1
debug1: identity file /Users/wcyang/.ssh/id_rsa type 1
debug1: identity file /Users/wcyang/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.1p1 Debian-5
debug1: match: OpenSSH_5.1p1 Debian-5 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.2
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 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: Host 'dl.sv.gnu.org' is known and matches the RSA host key.
debug1: Found key in /Users/wcyang/.ssh/known_hosts:1
debug1: ssh_rsa_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: /Users/wcyang/.ssh/identity
debug1: Offering public key: /Users/wcyang/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/wcyang/.ssh/id_dsa
debug1: No more authentication methods to try.
Permission denied (publickey).
lost connection

答案1

您是否希望系统提示您输入密码?如果是这样,则说明您的 ssh 或远程服务器的 sshd 配置中已发生更改,以禁止密码验证。

否则,您的调试输出似乎表明您的私钥与远程帐户的 .ssh 目录中的任何公钥都不匹配。您是否将savannah 上的文件与本地机器上的~/.ssh/id_?sa.pub输出进行了比较?ssh-keygen -y

另一种可能性是你的 .ssh 文件的权限太宽松。我相信我已经看到过这种情况发生,没有任何输出、调试或其他方式来暗示它。

答案2

这是一个authentication error,有not a matching key配对 。

当遇到问题ssh或使用ssh过度scp时,-v 开关对于诊断问题非常有用,v您在其中输入的越多verbose,输出就越多:

scp -vvv -P 30000 /somedir/somedir/file user@domain:/somedir/somedir/

以下是它的示例输出:

OpenSSH_6.7p1 Debian-5+deb8u7, OpenSSL 1.0.1t  3 May 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to 192.168.1.171 [192.168.1.171] port 30000.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/identity type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/identity-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4p1 Debian-10+deb9u4
debug1: match: OpenSSH_7.4p1 Debian-10+deb9u4 pat OpenSSH* compat 0x04000000
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.7p1 Debian-5+deb8u7
debug2: fd 3 setting O_NONBLOCK
debug3: put_host_port: [192.168.1.171]:30000
debug3: load_hostkeys: loading entries for host "[192.168.1.171]:30000" from file "/root/.ssh/known_hosts"
debug3: load_hostkeys: found key type ECDSA in file /root/.ssh/known_hosts:7
debug3: load_hostkeys: loaded 1 keys
debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received

您可以检查文件是否permissions设置ssh正确,您可以permissions在我的ls命令中看到以下内容

可能有人key从服务器上删除了您的信息。

或者正如评论中有人说的那样,也许你没有matching private key


如果在此阶段有人需要创建一个ssh key,您可以这样做:

ssh-keygen -o -b 4096 -t rsa -C [email protected]

这会创建一个private key和目录public key中的一个~/.ssh/,小心不要共享你的私钥,这就是id_rsa....注意它~/.ssh/前面有一个点,因为它是一个隐藏目录,如下所示:

$ls -sail .ssh/
total 20
  658 4 drwx------  2 user user 4096 Nov 10 06:05 .
   12 4 drwxr-xr-x 47 user user 4096 Nov 10 06:11 ..
34211 4 -rw-r--r--  1 user user 1487 Nov  1 02:37 authorized_keys
34375 4 -rw-------  1 user user 3434 Nov 10 06:05 id_rsa
34376 4 -rw-r--r--  1 user user  749 Nov 10 06:05 id_rsa.pub
  664 0 -rw-r--r--  1 user user   0 Nov 10 06:04 known_hosts

然后将密钥复制到服务器:

cat ~/.ssh/id_rsa.pub | ssh -p 30000 something@SERVER 'cat >> .ssh/authorized_keys'

您需要进入public ssh key服务器,如果您无法以物理方式访问它,则可以编辑sshd_config以允许密码

 # Change to no to disable tunnelled clear text passwords
 PasswordAuthentication no

当你复制它时,你可以email将它复制到system administrator,然后他就可以将其放到服务器上。

答案3

这为我解决了这个问题:

ssh-keygen -f "/home/local/.../.ssh/known_hosts" -R

相关内容