已断开连接:没有可用的受支持的身份验证方法

已断开连接:没有可用的受支持的身份验证方法

我遇到了与描述中完全相同的问题此主题但那里接受的答案对我来说并不正确,因为用户的主目录当地的。

我认为我已经在客户端正确配置了所有内容(Windows 7、PuTTY 的 PAGEANT、PUTTYGEN 和 PLINK),但我似乎无法使公钥机制正常工作(基于密码的 ssh 登录有效)。我遵循了以下所有步骤、提示和提示:

我现在怀疑我可能在服务器端(Linux,sshd)遗漏了一些东西,所以我发布了当前的/etc/ssh/sshd_config内容:

Protocol 2
SyslogFacility AUTHPRIV
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys
PasswordAuthentication no
PermitEmptyPasswords yes
ChallengeResponseAuthentication no
UsePAM yes
X11Forwarding yes
Subsystem       sftp    /usr/libexec/openssh/sftp-server

知道我做错了什么吗?

更新:我找到了跑步的小窍门sshd 处于调试模式,输出如下:

/home/winwin> /usr/sbin/sshd -d
debug1: sshd version OpenSSH_4.2p1
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: Bind to port 22 on ::.
Server listening on :: port 22.
debug1: Bind to port 22 on 0.0.0.0.
Bind to port 22 on 0.0.0.0 failed: Address already in use.
debug1: Server will not fork when running in debugging mode.
debug1: rexec start in 4 out 4 newsock 4 pipe -1 sock 7
debug1: inetd sockets after dupping: 3, 3
Connection from 192.168.1.8 port 49828
debug1: Client protocol version 2.0; client software version PuTTY_Release_0.60
debug1: no match: PuTTY_Release_0.60
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.2
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 aes256-ctr hmac-sha1 none
debug1: kex: server->client aes256-ctr hmac-sha1 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST_OLD 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 winwin service ssh-connection method none
debug1: attempt 0 failures 0
debug1: PAM: initializing for "winwin"
debug1: PAM: setting PAM_RHOST to "win7client"
debug1: PAM: setting PAM_TTY to "ssh"
Failed none for winwin from 192.168.1.8 port 49828 ssh2
debug1: userauth-request for user winwin service ssh-connection method publickey
debug1: attempt 1 failures 1
debug1: test whether pkalg/pkblob are acceptable
debug1: temporarily_use_uid: 513/513 (e=0/0)
debug1: trying public key file /home/winwin/.ssh/authorized_keys
Authentication refused: bad ownership or modes for directory /home/winwin
debug1: restore_uid: 0/0
debug1: temporarily_use_uid: 513/513 (e=0/0)
debug1: trying public key file /home/winwin/.ssh/authorized_keys
Authentication refused: bad ownership or modes for directory /home/winwin
debug1: restore_uid: 0/0
Failed publickey for winwin from 192.168.1.8 port 49828 ssh2
Received disconnect from 192.168.1.8: 14: No supported authentication methods available
debug1: do_cleanup
debug1: PAM: cleanup
debug1: do_cleanup
debug1: PAM: cleanup

现在,我确实注意到了这两条bad ownership or modes for directory /home/winwin消息,但是我检查了目录 /home/winwin 的所有权或模式,并且 AFAICT 它们没问题:

/home> ls -lad winwin
drwxrwxr-x  21 winwin winwin 4096 Jul 13 21:24 winwin

和:

/home/winwin> ls -lad .ssh
drwxr-xr-x  2 winwin winwin 4096 Jul 14 12:06 .ssh

和:

/home/winwin/.ssh> ls -lad *
-rw-r--r--  1 winwin winwin 210 Jul 14 12:06 authorized_keys
-rw-r--r--  1 winwin winwin 210 Jul 14 01:58 authorized_keys.pub
-rw-r--r--  1 winwin winwin 394 Jul 14 01:57 authorized_keys.pub.orig

可能存在什么问题?

更新二:chmod 600按照以下答案中的建议进行了尝试:

/home/winwin> ls -lad .ssh
drw-------  2 winwin winwin 4096 Jul 14 13:13 .ssh

和:

/home/winwin/.ssh> ls -lad *
-rw-------  1 winwin winwin 210 Jul 14 12:06 authorized_keys

但它仍然不起作用。为什么我仍然收到错误Authentication refused: bad ownership or modes for directory /home/winwin

答案1

尝试从您的主目录获取组的可写权限:

chmod g-w ~/

使您的 .ssh 文件夹可读/可写/可执行只由你

chmod 700 ~/.ssh

使您的授权密钥文件可读/可写只由你

chmod 600 ~/.ssh/authorized_keys

这应该可以消除权限错误。

答案2

成功!

我所要做的就是StrictModes改变

第3.14节在 OpenSSH FAQ 和http://blogs.nullvision.com/?p=114

哇。

答案3

遇到过类似的问题。在四处查看时,我发现我的主目录已加密,并怀疑这就是问题所在。我将授权密钥文件复制到加密主目录之外的目录中,并适当更改了权限(chmod 700 [dir]、chmod 600 [dir]/authorized_keys 等)。

然后编辑你的 sshd_config 来告诉 sshd 授权密钥文件的新位置,重新启动 sshd,就这样。

似乎已经解决了我的问题。

答案4

我努力解决了这个问题,最终找到了一个不会导致潜在安全漏洞的解决方案,例如严格模式做。

确保您的设置如下:

chmod 0755 /home/{用户目录}

chmod 0700 /home/{用户目录}/.ssh

chmod 0600 /home/{用户目录}/.ssh/authorized_keys

其中 {userdir} 是所讨论的目录。

关键是 chmod 0755,它确保只有用户可以写入主驱动器。我从我的用户配置中复制了这个,并且,瞧!其他用户名也开始起作用了!

希望这能像我一样帮助其他人,并为您节省几个小时的时间。

相关内容