尽管匹配,sshd 仍拒绝公钥?

Luk*_*eLR 5 linux ssh nas openssh

我在 Synology NAS 上使用 DSM 6 附带的 OpenSSH 6.8 作为服务器,在 Arch Notebook 上使用 OpenSSH 7.3p1 作为客户端。我可以通过密码以默认用户身份登录admin,但不能通过密钥登录,并且不明白为什么。

奇怪的是:服务器似乎接受了我的公钥,但仍然推迟?

...
debug1: userauth-request for user admin service ssh-connection method publickey [preauth]
debug1: attempt 1 failures 0 [preauth]
debug1: test whether pkalg/pkblob are acceptable [preauth]
debug1: temporarily_use_uid: 1024/100 (e=0/0)
debug1: trying public key file /var/services/homes/admin/.ssh/authorized_keys
debug1: fd 5 clearing O_NONBLOCK
debug1: matching key found: file /var/services/homes/admin/.ssh/authorized_keys, line 1 RSA SHA256:Kq+mYIESxPced3WZ0/GXkKeYxzn5aLI8P0S8MoVPll4
debug1: restore_uid: 0/0
Postponed publickey for admin from <client IP> port 43226 ssh2 [preauth]
...
Run Code Online (Sandbox Code Playgroud)

我已经尝试过多次重新启动两台计算机和sshd,以及对用户管理员的主文件夹及其目录的几乎所有可能的访问权限.ssh。但这似乎不是问题。这里有什么问题吗?

任何想法都将不胜感激!预先感谢,
卢卡斯

编辑:客户端在探测密钥后说:“代理拒绝操作”:

debug1: Offering RSA public key: /home/client/.ssh/id_rsa
debug3: send_pubkey_test
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 60
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug2: input_userauth_pk_ok: fp SHA256:Kq+m***
debug3: sign_and_send_pubkey: RSA SHA256:Kq+m***
sign_and_send_pubkey: signing failed: agent refused operation
Run Code Online (Sandbox Code Playgroud)

此外,我已在此处上传了详细客户端和服务器会话的完整输出。

Luk*_*eLR 1

这很可能是您服务器上的关键文件权限的问题。确保您的.ssh文件夹、其中的文件以及文件.ssh夹所在的主目录具有限制性权限。如果关键操作的权限过于宽松,OpenSSH 服务器会拒绝这些操作。这意味着,任何超出的事情700通常都会被拒绝。

如果权限不正确,OpenSSH 服务器会打印警告,但仅作为调试级别 3,因此它们不会出现在正常输出或正常调试模式中。此外,只有当有人尝试连接时才会出现权限警告。运行sshd -D -ddd -e以启用第三级调试并使 OpenSSH 打印有关关键文件权限的警告。确保先停止您的 OpenSSH 服务器,以防它正在运行。

然后,OpenSSH 服务器将等待任何传入连接,但不会分叉到后台,因此所有输出都会打印到stdout. 因此,您可以在尝试从客户端之一建立 SSH 连接时观看 OpenSSH 服务器。如果您在尝试登录时看到权限警告,请尝试以下命令来修复您的权限:

chmod 700 ~
chmod 700 -R ~/.ssh
Run Code Online (Sandbox Code Playgroud)

其中~是您要通过 ssh 访问的用户的主目录。

之后重新启动 OpenSSH 服务器并查看问题是否已解决:)