问题

问题

问题

尝试从两台不同的计算机连接到我的 QNAP 服务器,之前可以通过ssh 没有密码——但是现在每次都会要求输入密码。出了什么问题?我该如何解决?

我尝试过的方法

我到处寻找想法并检查了以下内容,但均未成功:

  • 将客户端的公钥添加到服务器:( ~/.ssh/authorized_keys)。

  • 设置文件权限:服务器上的管理员(root)帐户已运行以下两项:

    chmod 700 ~/.ssh/

    chmod 600 ~/.ssh/*

  • 重新创建并上传密钥

附加信息

我想不出与这些键不再起作用的时间线相匹配的更新,所以我不知道为什么它们会突然停止运转。

@Yevhen-Stasiv 建议检查我的配置——事实证明,每次服务器重启时都会重置此文件;尽管如此,其值仍然是:

[~/.ssh] # cat sshd_config
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
PermitRootLogin yes
UseDNS no
Subsystem sftp /usr/libexec/sftp-server
AllowTcpForwarding no
AllowUsers admin

我的服务器上的 OpenSSL 版本是:

# ssh -V
OpenSSH_8.0p1, OpenSSL 1.0.2k  26 Jan 2017

我不确定这是否有什么区别,但事实就是如此。

最后,增加命令的详细程度(并阻止密码验证),这就是我所看到的:

$ ssh -vv -o PasswordAuthentication=no admin@nasdekleer
OpenSSH_8.1p1, OpenSSL 1.1.1d  10 Sep 2019
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: resolving "nasdekleer" port 22
debug2: ssh_connect_direct
debug1: Connecting to nasdekleer [10.132.197.180] port 22.
debug1: Connection established.
debug1: identity file /c/Users/Ryan/.ssh/id_rsa type 0
debug1: identity file /c/Users/Ryan/.ssh/id_rsa-cert type -1
debug1: identity file /c/Users/Ryan/.ssh/id_dsa type -1
debug1: identity file /c/Users/Ryan/.ssh/id_dsa-cert type -1
debug1: identity file /c/Users/Ryan/.ssh/id_ecdsa type -1
debug1: identity file /c/Users/Ryan/.ssh/id_ecdsa-cert type -1
debug1: identity file /c/Users/Ryan/.ssh/id_ed25519 type -1
debug1: identity file /c/Users/Ryan/.ssh/id_ed25519-cert type -1
debug1: identity file /c/Users/Ryan/.ssh/id_xmss type -1
debug1: identity file /c/Users/Ryan/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.0
debug1: match: OpenSSH_8.0 pat OpenSSH* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to nasdekleer:22 as 'admin'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal

[...output omitted for brevity...]

debug1: Server host key: ssh-rsa SHA256:/WeVhQddipMcY6dZdQ+HgL+kMhsUEqRqLEsdpK14MNM
debug1: Host 'nasdekleer' is known and matches the RSA host key.
debug1: Found key in /c/Users/Ryan/.ssh/known_hosts:1
debug2: set_newkeys: mode 1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /c/Users/Ryan/.ssh/id_rsa RSA SHA256:1sWIuTIkFdDZ9cxqz1va1Y+SnAXAkL61/0lLTe9fW5c
debug1: Will attempt key: /c/Users/Ryan/.ssh/id_dsa
debug1: Will attempt key: /c/Users/Ryan/.ssh/id_ecdsa
debug1: Will attempt key: /c/Users/Ryan/.ssh/id_ed25519
debug1: Will attempt key: /c/Users/Ryan/.ssh/id_xmss
debug2: pubkey_prepare: done
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering public key: /c/Users/Ryan/.ssh/id_rsa RSA SHA256:1sWIuTIkFdDZ9cxqz1va1Y+SnAXAkL61/0lLTe9fW5c
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Trying private key: /c/Users/Ryan/.ssh/id_dsa
debug1: Trying private key: /c/Users/Ryan/.ssh/id_ecdsa
debug1: Trying private key: /c/Users/Ryan/.ssh/id_ed25519
debug1: Trying private key: /c/Users/Ryan/.ssh/id_xmss
debug2: we did not send a packet, disable method
debug1: Next authentication method: keyboard-interactive
debug2: userauth_kbdint
debug2: we sent a keyboard-interactive packet, wait for reply
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
admin@nasdekleer: Permission denied (publickey,password,keyboard-interactive).

更新

我无法追踪服务器上的日志,但是我发现我可以通过登录服务器并运行以下命令在不同的端口上运行我自己的 ssh 守护程序:

/usr/sbin/sshd -p 50023 -D -d -e -f /etc/config/ssh/sshd_config

...然后进入我的客户端并尝试像这样登录:

ssh -v -p 50023 admin@nasdekleer

然后在服务器端就可以看到输出:

[ ... ]

debug1: userauth-request for user admin service ssh-connection method none [preauth]
debug1: attempt 0 failures 0 [preauth]
debug1: userauth-request for user admin service ssh-connection method publickey [preauth]
debug1: attempt 1 failures 0 [preauth]
debug1: userauth_pubkey: test pkalg rsa-sha2-512 pkblob RSA SHA256:1sWIuTIkFdDZ9cxqz1va1Y+SnAXAkL61/0lLTe9fW5c [preauth]
debug1: temporarily_use_uid: 0/0 (e=0/0)
debug1: trying public key file /root/.ssh/authorized_keys
debug1: fd 4 clearing O_NONBLOCK
Authentication refused: bad ownership or modes for directory /mnt/HDA_ROOT

[...]

所以就是看似对我来说这可能仍然是文件权限问题?

答案1

因此,从服务器获取更多信息肯定是关键。

使用以下命令在服务器上打开 ssh 守护程序:

/usr/sbin/sshd -p 50023 -D -d -e -f /etc/config/ssh/sshd_config

并尝试使用以下命令从客户端登录:

ssh -v -p 50023

看到消息:

Authentication refused: bad ownership or modes for directory /mnt/HDA_ROOT

使用 检查目录ll /mnt,得到以下输出:

drwxr-xr-x   10 admin    administ       220 Jan  8 17:44 ./
drwxr-xr-x   20 admin    administ       480 Jan  8 19:35 ../
drwxrwxrwx   12 httpdusr administ      4.0k Jan  8 17:44 HDA_ROOT/

哎呀。我肯定以某种方式更改了根主目录的所有权为网络服务器设置一些东西时!

将所有权转回chown admin /mnt/HDA_ROOT

现在一切都又恢复正常了!:D

答案2

问题很可能出在服务器端。软件更新可能重写了 sshd 配置,请验证配置是否仍设置为允许密钥认证。

查看 sshd 日志文件寻找任何线索,如果没有任何内容,请尝试在前台和调试模式下运行 sshd 以快速查看发生了什么。

相关内容