I'm trying out Kerberos on two VMs running CentOS 7. One VM acts as the server and the other one as a client host where users are supposed to log in.
My complete setup is shown below. When I create a new user to test my setup, this user can SSH (or directly login) into the client host and he automatically gets a Kerberos TGT (klist
). But if I run passwd
to change the password, I get an error.
In the log (via journalctl
) I see the following messages when authenticating for the password change (with the old password):
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
Then I enter the new password twice and get these additional messages in the log:
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 demouser@EXAMPLE.COM: 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
Then on the console I get this message:
passwd: Authentication token manipulation error
Any idea why the login works but the password change doesn't? And how I can fix this?
Server configuration (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
Client configuration (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
Test with new user
-
Create user principal on the server (VM1)
kadmin addprinc demouser quit
-
Create local user on the client (VM2)
useradd -m -s /bin/bash demouser
-
Log in and change password (from workstation)
ssh demouser@krbclient passwd
Best Answer
I found the solution: The following command was missing in the server setup:
(immediately before the
firewall-cmd --reload
)