在 CentOS 7 上配置 Kerberos/PAM

在 CentOS 7 上配置 Kerberos/PAM

我正在两台运行 CentOS 7 的虚拟机上试用 Kerberos。一台虚拟机充当服务器,另一台虚拟机充当用户应该登录的客户端主机。

我的完整设置如下所示。当我创建一个新用户来测试我的设置时,该用户可以通过 SSH(或直接登录)进入客户端主机,并自动获得 Kerberos TGT(klist)。但如果我运行passwd更改密码,则会收到错误。

在日志中(通过journalctl),我在验证密码更改(使用旧密码)时看到以下消息:

unix_chkpwd[8790]: password check failed for user (demouser)
passwd[8788]: pam_unix(passwd:chauthtok): authentication failure; logname= uid=1001 euid=0 tty=pts/2 ruser= rhost=  user=demouser

然后我输入两次新密码并在日志中收到以下附加消息:

unix_chkpwd[8792]: password check failed for user (demouser)
passwd[8788]: pam_unix(passwd:chauthtok): user password changed by another process
passwd[8788]: pam_krb5[8788]: password change failed for [email protected]: Cannot contact any KDC for requested realm
passwd[8788]: PAM 1 more authentication failure; logname= uid=1001 euid=0 tty=pts/2 ruser= rhost=  user=demouser

然后在控制台上我收到以下消息:

passwd: Authentication token manipulation error

知道为什么登录有效但密码更改无效吗?我该如何解决这个问题?


服务器配置(VM1)

# collect input
DOMAIN=$(hostname -d)
REALM=$(echo "$DOMAIN" | tr '[:lower:]' '[:upper:]')
read -s -p "Kerberos DB Master Password: " KRB_DBMASTER_PW && echo
read -s -p "Kerberos root/admin Password: " KRB_ROOT_PW && echo

# setup ntp
yum -y install ntp
systemctl start ntpd
systemctl enable ntpd

# install kerberos
yum -y install krb5-server krb5-workstation

# replace realm and domain in krb5.conf
sed -i 's|^\(# Confi\)|#\1|' /etc/krb5.conf
sed -i 's|^#||' /etc/krb5.conf
sed -i "s|EXAMPLE\.COM|$REALM|" /etc/krb5.conf
sed -i "s|kerberos\.example\.com|$(hostname -f)|" /etc/krb5.conf
sed -i "s|example\.com|$DOMAIN|" /etc/krb5.conf

# replace realm in kdc.conf and kadm5.acl
sed -i "s|EXAMPLE\.COM|$REALM|" /var/kerberos/krb5kdc/kdc.conf
sed -i "s|EXAMPLE\.COM|$REALM|" /var/kerberos/krb5kdc/kadm5.acl

# initialize kerberos db
echo -e "${KRB_DBMASTER_PW}\n${KRB_DBMASTER_PW}" | kdb5_util create -s -r $REALM

# start kerberos services
systemctl enable kadmin
systemctl enable krb5kdc
systemctl start kadmin
systemctl start krb5kdc
firewall-cmd --permanent --add-service kerberos
firewall-cmd --reload

# add root/admin principal
cat <<-EOF | kadmin.local
    addprinc root/admin
    $KRB_ROOT_PW
    $KRB_ROOT_PW
    quit
EOF

客户端配置(VM2)

# collect input
DOMAIN=$(hostname -d)
REALM=$(echo "$DOMAIN" | tr '[:lower:]' '[:upper:]')
read -p "Server hostname: " SERVER_HOSTNAME
read -s -p "Kerberos root/admin Password: " KRB_ROOT_PW && echo

# setup ntp
yum -y install ntp
systemctl start ntpd
systemctl enable ntpd

# setup kerberos
yum -y install krb5-workstation pam_krb5

# create host principal for this client on the kerberos server
cat <<-EOF | ssh -t $SERVER_HOSTNAME "sudo kadmin.local ; sudo chown $USER /tmp/$(hostname -s).keytab"
    addprinc -randkey host/$(hostname -f)
    ktadd -k /tmp/$(hostname -s).keytab host/$(hostname -f)
    quit
EOF
scp $SERVER_HOSTNAME:\{/tmp/$(hostname -s).keytab,/etc/krb5.conf\} /tmp

# replace krb5.conf
cp /tmp/krb5.conf /etc

# import host key on client
cat <<-EOF | ktutil
    rkt /tmp/$(hostname -s).keytab
    wkt /etc/krb5.keytab
    quit
EOF

# configure pam
authconfig --enablekrb5 --update

与新用户测试

  1. 在服务器(VM1)上创建用户主体

    kadmin
        addprinc demouser
        quit
    
  2. 在客户端(VM2)上创建本地用户

    useradd -m -s /bin/bash demouser
    
  3. 登录并更改密码(从工作站)

    ssh demouser@krbclient
        passwd
    

答案1

我找到了解决方案:服务器设置中缺少以下命令:

firewall-cmd --permanent --add-service kpasswd

(紧接在 之前firewall-cmd --reload

相关内容