即使使用 ssh-copy-id 命令交换密钥后,在 ssh 连接到服务器时仍始终提示输入密码

即使使用 ssh-copy-id 命令交换密钥后,在 ssh 连接到服务器时仍始终提示输入密码

ssh -vvv 用户名@server_ip 的输出

debug2: reserved 0
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug3: send packet: type 30
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug3: receive packet: type 31
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:cD7xKnHDgWT3LV6TDozzJrMzzJ+3v486OtG14S5Qpi4
debug3: hostkeys_foreach: reading file "/root/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /root/.ssh/known_hosts:14
debug3: load_hostkeys: loaded 1 keys from <server_ip>
debug1: Host '10.49.233.6' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:14
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: receive packet: type 21
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey after 134217728 blocks
debug2: key: /root/.ssh/id_rsa (0x7fffbcf571f0)
debug2: key: /root/.ssh/id_dsa ((nil))
debug2: key: /root/.ssh/id_ecdsa ((nil))
debug2: key: /root/.ssh/id_ed25519 ((nil))
debug3: send packet: type 5
debug3: receive packet: type 7
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug3: start over, passed a different list publickey,gssapi-keyex,gssapi-with-mic,password
debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup gssapi-keyex
debug3: remaining preferred: gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_is_enabled gssapi-keyex
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
debug2: we did not send a packet, disable method
debug3: authmethod_lookup gssapi-with-mic
debug3: remaining preferred: publickey,keyboard-interactive,password
debug3: authmethod_is_enabled gssapi-with-mic
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
No Kerberos credentials available (default cache: FILE:/tmp/krb5cc_0)

debug1: Unspecified GSS failure.  Minor code may provide more information
No Kerberos credentials available (default cache: FILE:/tmp/krb5cc_0)

debug2: we did not send a packet, disable method
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:ZhQDTeqcqksWszlfmpjcdF4GuGsejY8/zHHNp9fbB+Y /root/.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 51
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: /root/.ssh/id_dsa
debug3: no such identity: /root/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /root/.ssh/id_ecdsa
debug3: no such identity: /root/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /root/.ssh/id_ed25519
debug3: no such identity: /root/.ssh/id_ed25519: No such file or directory
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password

服务器端文件权限

drwxr-xr-x.   2 root root        225 Jun 16 02:48 .
drwxr-xr-x. 146 root root      12288 Jun 11 02:07 ..
-rw-r--r--.   1 root root     581843 Aug  8  2019 moduli
-rw-r--r--.   1 root root       2276 Aug  8  2019 ssh_config
-rw-r-----.   1 root ssh_keys    227 May 13 04:24 ssh_host_ecdsa_key
-rw-r--r--.   1 root root        162 May 13 04:24 ssh_host_ecdsa_key.pub
-rw-r-----.   1 root ssh_keys    387 May 13 04:24 ssh_host_ed25519_key
-rw-r--r--.   1 root root         82 May 13 04:24 ssh_host_ed25519_key.pub
-rw-r-----.   1 root ssh_keys   1675 May 13 04:24 ssh_host_rsa_key
-rw-r--r--.   1 root root        382 May 13 04:24 ssh_host_rsa_key.pub
-rwxr--r--.   1 root root       3927 Jun 16 02:46 sshd_config

[root@machine-name ~]# ls -l .ssh/
total 12
-rw-------. 1 root root 1675 Jun 16 07:58 id_rsa
-rw-r--r--. 1 root root  400 Jun 16 07:58 id_rsa.pub
-rw-r--r--. 1 root root  175 May 27 07:40 known_hosts

[root@machine-name ~]# ls -la ~/
drwxrwxrwx.  2 root root    25 May 27 07:40 .ssh

sshd_config 文件内容

Port 22
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
SyslogFacility AUTHPRIV
RSAAuthentication yes
PubkeyAuthentication yes
PasswordAuthentication yes
ChallengeResponseAuthentication no
GSSAPIAuthentication yes
GSSAPICleanupCredentials no
UsePAM yes
X11Forwarding yes
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS
Subsystem   sftp    /usr/libexec/openssh/sftp-server

我尝试注释掉并取消注释以下行,但仍然面临同样的问题。每次更改后/etc/init.d/sshd restart

AuthorizedKeysFile .ssh/authorized_keys

我可以在密钥交换后无密码登录其他服务器,但只有这台特定的服务器不断询问密码。PS
- 源是 ubuntu 系统,目标也是另一个 CentOS Linux 系统

相关内容