【问题标题】:"Connection closed by [HOST IP]" using dsa key authentication“连接由 [HOST IP] 关闭”使用 dsa 密钥身份验证
【发布时间】:2012-04-23 04:41:44
【问题描述】:

我使用 Perceus 集群软件 (http://perceus.org) 为我们的集群设置了一个共享的 /home。节点使用 CentOS 6.1 x86_64。 /home 由 nfs (NFSv4) 从头到节点共享。

root@head~]$ cat /etc/exports 
/var/lib/perceus/ 10.10.10.0/255.255.255.0(ro,no_root_squash,async)
/home/ 10.10.10.0/255.255.255.0(rw,no_root_squash,no_all_squash,async)

这里是每个节点上的/etc/fstab(都一样)。

...
10.10.10.2:/var/lib/perceus/ /var/lib/perceus/ nfs ro,soft,bg 0 0
10.10.10.2:/home/ /home nfs rw,soft,bg 0 0

节点上的/etc/fstab 是具有相同UID:GID 的head/master 的副本。

我使用以下方法创建了密钥对:

$ cd ~
$ rm -rf .ssh
$ mkdir .ssh
$ chmod 700 .ssh
$ ssh-keygen -t dsa -P ""
Generating public/private dsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_dsa):
Your identification has been saved in /home/user/.ssh/id_dsa.
Your public key has been saved in /home/user/.ssh/id_dsa.pub.
The key fingerprint is:
[SNIPPED] user@head
The key's randomart image is:
+--[ DSA 1024]----+
[SNIPPED]
$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
$ chmod 400 ~/.ssh/authorized_keys

问题出在这里。 当我尝试 ssh 进入每个节点时,我收到“连接已关闭” 错误。这是调试输出。

$ ssh node01
Connection closed by 10.10.10.101

$ ssh node01 -vvv
OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to node01 [10.10.10.101] port 22.
debug1: Connection established.
debug1: identity file /home/user/.ssh/identity type -1
debug1: identity file /home/user/.ssh/id_rsa type -1
debug3: Not a RSA1 key file /home/user/.ssh/id_dsa.
debug2: key_type_from_name: unknown key type '-----BEGIN'
debug3: key_read: missing keytype
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug2: key_type_from_name: unknown key type '-----END'
debug3: key_read: missing keytype
debug1: identity file /home/user/.ssh/id_dsa type 2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3
.... SNIPPED ...
debug2: dh_gen_key: priv key bits set: 139/256
debug2: bits set: 482/1024
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug3: Wrote 144 bytes for a total of 981
debug3: check_host_in_hostfile: filename /home/user/.ssh/known_hosts
debug3: check_host_in_hostfile: match line 1
debug3: check_host_in_hostfile: filename /home/user/.ssh/known_hosts
debug3: check_host_in_hostfile: match line 1
debug1: Host 'node01' is known and matches the RSA host key.
debug1: Found key in /home/user/.ssh/known_hosts:1
debug2: bits set: 501/1024
debug1: ssh_rsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: Wrote 16 bytes for a total of 997
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug3: Wrote 48 bytes for a total of 1045
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /home/user/.ssh/identity ((nil))
debug2: key: /home/user/.ssh/id_rsa ((nil))
debug2: key: /home/user/.ssh/id_dsa (0x7f79b940f650)
debug3: Wrote 64 bytes for a total of 1109
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
... [SNIPPED]...
debug1: Next authentication method: publickey
debug1: Trying private key: /home/user/.ssh/identity
debug3: no such identity: /home/user/.ssh/identity
debug1: Trying private key: /home/user/.ssh/id_rsa
debug3: no such identity: /home/user/.ssh/id_rsa
debug1: Offering public key: /home/user/.ssh/id_dsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug3: Wrote 528 bytes for a total of 1637
debug1: Server accepts key: pkalg ssh-dss blen 434
debug2: input_userauth_pk_ok: SHA1 fp 46:a2:c3:86...........
debug3: sign_and_send_pubkey
debug1: read PEM private key done: type DSA
debug3: Wrote 592 bytes for a total of 2229
Connection closed by 10.10.10.101

我已确保 /etc/ssh/sshd_config 允许基于密钥的身份验证(PubkeyAuthentication yes)。 我已确保 /home 上的权限(一旦安装在节点上)是正确的。用户已正确验证。 我已经尝试过使用和不使用“no_all_squash”重新启动 nfs、rpcidmap、rpcbind 和 nfslock 的情况下挂载 nfs。

我已经在具有不同主/头节点的节点上安装了 CentOS5。 CentOS6 似乎给我带来了额外的问题。

如果我不创建密钥,当然会提示我输入密码。

我的 hosts.allow/deny 在客户端和服务器上都是空的。

root 用户可以连接。 Perceus 为 root 用户处理密钥生成,因为它是虚拟文件系统的一部分。我猜我的密钥生成有问题,但我不知道是什么问题。

【问题讨论】:

  • 连接时看看/var/log/secure*
  • 找到:fatal: Access denied for user user by PAM account configuration

标签: ssh openssh


【解决方案1】:

正确的解决方案是解决问题,而不是禁用 pam,因为您可能隐藏了安全问题。

ssh 失败是因为 PAM 通过一些检查失败来拒绝用户登录。 验证 /etc/pam.d/sshd 以了解您有哪些规则以及哪些可能失败。

最常见的问题是用户没有密码(比较/etc/passwd/etc/shadow,或者检查您的/etc/nsswitch/etc/pam.d/* 以查看用户和身份验证的来源),但也没有主目录,缺少一些额外的身份验证配置、UID 太低或太高等。

如果它丢失了密码,至少在/etc/ssh/sshd_config 中确保你这样做

PermitEmptyPasswords no

这会阻止 ssh 以允许没有密码的用户登录(但对其他协议没有任何作用,例如 telnet、ftp、http 和登录)。

【讨论】:

  • 感谢您的回答!!!我一直想知道为什么特定用户(gpadmin)无法在本地主机上进行 ssh,.ssh 中的其他所有内容都使用正确的权限正确设置——结果证明它是一个无密码用户。我刚刚做了sudo passwd gpadmin,现在用户可以像其他人一样在 localhost 上 ssh。
  • 感谢您的回答。我只是在 /etc/passwd 中克隆了一个用户,但没有在 /etc/shadow ...
  • 哎呀,你让我开心了:无密码登录怎么可能需要密码......?
  • @AxelAmthor:问题在于 PAM 需要在 /etc/shadow 中输入密码(即使该文件中的密码字段为空)来验证用户。也就是说,问题是用户验证,而不是真正的密码问题。 :)
  • “最常见的问题是用户没有密码”就是这样……
【解决方案2】:

解决方案:

按照下面的建议,我在节点(主机)上检查了/var/log/security。它显示:

fatal: Access denied for user user by PAM account configuration

然后我编辑了/etc/ssh/sshd_config更改:

UsePAM yes

UsePAM no

重新启动节点,我现在可以执行无密码登录。

谢谢!

【讨论】:

    【解决方案3】:

    使用无密码授权是不好的。 selinux 是否打开了这些服务器?如果是,那么您必须关闭 selinux,或者通过“restorecon -R -v /home/user/. This is a known issue

    【讨论】:

      【解决方案4】:

      我遇到了和你非常相似的问题。

      原来我的问题,也可能是你的问题,是因为我的主目录是 NFS 挂载,而 selinux(在 CentOS 7 上)抛出了一些错误(很难追踪)。不过修复很简单。

      setsebool -P use_nfs_home_dirs 1
      

      【讨论】:

        【解决方案5】:

        在我的例子中,我没有使用 useradd 创建用户,而是在 /etc/passwd 文件中添加了用户,并为用户创建了包含所有必需文件的主目录。

        使用useradd创建用户,并在用户主目录下创建.ssh目录后,将pub key添加到authorized_keys文件,问题得到解决。

        顺便说一句,我使用的是centos 7

        希望这对某人有所帮助。

        【讨论】:

          【解决方案6】:

          对我来说,我有损坏的 pam.d 文件。我从类似的服务器复制了一套新的,一切都很好。我没有花时间寻找具体的损坏,但我想我会添加我的 2 位,以防将来有人阅读此内容并需要更多想法。

          【讨论】:

            猜你喜欢
            • 2021-01-04
            • 1970-01-01
            • 1970-01-01
            • 2023-01-30
            • 2022-01-18
            • 1970-01-01
            • 1970-01-01
            • 2017-05-16
            • 2019-09-04
            相关资源
            最近更新 更多