如果您具有对服务器的root访问权,则解决此类问题的简单方法是在调试模式下运行sshd,方法是/usr/sbin/sshd -d -p 2222
在服务器上发出类似的内容(需要sshd可执行文件的完整路径,这which sshd
会有所帮助),然后使用来从客户端进行连接ssh -p 2222 user@host
。这将强制SSH守护程序停留在前台并显示有关每个连接的调试信息。寻找类似的东西
debug1: trying public key file /path/to/home/.ssh/authorized_keys
...
Authentication refused: bad ownership or modes for directory /path/to/home/
如果无法使用备用端口,则可以暂时停止SSH守护程序,并在调试模式下将其替换为一个。停止SSH守护程序不会杀死现有的连接,因此可以通过远程终端执行此操作,但是这样做有些冒险-如果在调试替换未运行时确实由于某种原因断开了连接,则您将被锁定在计算机之外直到您可以重新启动它。所需的命令:
service ssh stop
/usr/sbin/sshd -d
#...debug output...
service ssh start
(取决于您的Linux发行版,第一行/最后一行可能是systemctl stop sshd.service
/ systemctl start sshd.service
。)
我的执行 ,看不懂什么有价值的东西
[root@node2 ~]# /usr/sbin/sshd -d -p 2222
debug1: sshd version OpenSSH_4.3p2
debug1: read PEM private key done: type RSA
debug1: private host key: #0 type 1 RSA
debug1: read PEM private key done: type DSA
debug1: private host key: #1 type 2 DSA
debug1: rexec_argv[0]='/usr/sbin/sshd'
debug1: rexec_argv[1]='-d'
debug1: rexec_argv[2]='-p'
debug1: rexec_argv[3]='2222'
debug1: Bind to port 2222 on ::.
Server listening on :: port 2222.
debug1: Bind to port 2222 on 0.0.0.0.
Server listening on 0.0.0.0 port 2222.
debug1: Server will not fork when running in debugging mode.
debug1: rexec start in 5 out 5 newsock 5 pipe -1 sock 8
debug1: inetd sockets after dupping: 3, 3
Connection from 192.168.0.55 port 41929
debug1: Client protocol version 2.0; client software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.3
debug1: permanently_set_uid: 74/74
debug1: list_hostkey_types: ssh-rsa,ssh-dss
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST received
debug1: SSH2_MSG_KEX_DH_GEX_GROUP sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_INIT
debug1: SSH2_MSG_KEX_DH_GEX_REPLY sent
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: KEX done
debug1: userauth-request for user root service ssh-connection method none
debug1: attempt 0 failures 0
debug1: PAM: initializing for "root"
Address 192.168.0.55 maps to node2.magedu.com, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
debug1: PAM: setting PAM_RHOST to "192.168.0.55"
debug1: PAM: setting PAM_TTY to "ssh"