如何在CentOS7上使用Active Directoryauthentication使用cif和autofs来安装家庭目录?

我正在尝试使用Active Directy身份validation来集成CentOS7客户端,并使用cif自动安装用户homedirs。

我宁愿使用autofs,但到目前为止,我无法使用sec = krb5设置使cifs挂载工作。 这个消息总是失败

# mount -t cifs //fileserver.my.domain/user /mnt/user/ -orw,noperm,sec=krb5 mount error(126): Required key not available Refer to the mount.cifs(8) manual page (eg man mount.cifs) 

获取autofs与cifs和AD一起工作的任何提示将是最受欢迎的。

使用RedHat的这个描述来设置身份validation是一件容易的事情,只是添加了由

 realm discover MY.DOMAIN 

并运行该命令

 realm join MY.DOMAIN -U ad-admin-username 

所以身份validation工作正常,但获得cifs和kerberos工作是超越我。

我有一个解决方法使用pam_exec,但不觉得在pam框架中的文件共享的安装。

通过在/etc/pam.d/password-auth中插入以下行,最后列出的脚本将在密码validation时挂载正确的homedir。 在session_close中执行懒卸载,但可能不是正确的做法。

把它放到password-auth中

 auth optional pam_exec.so expose_authtok /usr/bin/pam_mount_cifs.s 

和这个

 session optional pam_exec.so /usr/bin/pam_mount_cifs.sh 

这两行应该在由realm连接命令插入的pam_mkhomedir行之后插入。

另一种方法是使用pam_mount(如本文所述),但是必须手动编译和安装pam_mount,因为它没有与CentOS一起提供。 (或从Nux回购 )

这里是脚本本身,它应该保存为/usr/bin/pam_mount_cifs.sh

 #!/bin/bash # this script is called from pam by adding entries to /etc/pam.d/password-auth like this # # auth optional pam_exec.so expose_authtok /usr/bin/pam_mount_cifs.sh # # and # # session optional pam_exec.so /usr/bin/pam_mount_cifs.sh # the script assumes that the home dir is already created by pam_mkhomedir and pam_oddjob_mkhomedir. DOMAIN=my.domain FILESERVER=fileserver.my.domain MNTPNT=/home # turn of globbing because getent returns as string containing a * set -f pwstring=$(getent passwd $PAM_USER) userinfo=(${pwstring//:/ }) USER=$PAM_USER # strip off @my.domain from user. SHORTUSER=${USER%@$DOMAIN} USERUID=${userinfo[2]} USERGID=${userinfo[3]} USERDIR=$MNTPNT/$USER if [ -z "$PAM_TYPE" ]; then echo this script should only be called from pam exit 1 fi if [ $PAM_TYPE = "open_session" ]; then # nothing to do here, mount happened in auth. exit 0 fi if [ $PAM_TYPE = "close_session" ]; then # this might cause problems if you have services that doesn't create procs in /home. (rstudio is one example) umount -l $USERDIR exit 0 fi if [ ! -d $USERDIR ]; then mkdir -p $USERDIR # chown $USERID:$USERGID $USERDIR fi # skip if the share is already mounted. mountpoint -q $USERDIR && exit 0 # make mount.cifs read password from stdin export PASSWD_FD=0 mount -t cifs //$FILESERVER/$SHORTUSER $USERDIR -o user=$SHORTUSER,uid=$USERUID,gid=$USERGID,noserverino