Autofs Issues Mounting NFS Home Directories (CentOS 7.4)

13,438

I figured it out. I was editing the /etc/auto.master on the server when I should have been doing it on the client. That is, on the client add the following to /etc/auto.master

/home/    /etc/auto.home

Still on the client, create the /etc/auto.home file and add the following to it

*    -nfs4,rw    &:/home/&

Finally restart autofs (on the client)

$ systemctl restart autofs

And that should do it. It is important to note that the user on the client should be the same as on the server (same username, same UID). This is usually accomplished using LDAP. Also, the home directory should only exist on the server, as autofs will create the mount point on the client for you.

Share:
13,438

Related videos on Youtube

Timothy Pulliam
Author by

Timothy Pulliam

Updated on September 18, 2022

Comments

  • Timothy Pulliam
    Timothy Pulliam almost 2 years

    I am having issues getting autofs to mount user's home directories via NFS. I have an NFS client (client.home) and an NFS server (server.home). Both systems are CentOS 7.4. SELinux is running in permissive mode on both systems. Can anyone point me into the right direction so I can automount user's home directories?

    NFS Export Table on server

    [root@server ~]# exportfs -v
    /home/tim       
    client.home(rw,sync,wdelay,hide,no_subtree_check,sec=sys,secure,root_squash,no_all_squash)
    

    The client can see these exports

    [root@client ~]# showmount -e server
    Export list for server:
    /home/tim client.home
    

    There are two users. One on the client, and one on the server. They both have the same name and UID. However, the user's home directory is only located on server.home.

    [tim@server ~]$ id
    uid=1001(tim) gid=1001(tim) groups=1001(tim) 
    context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
    
    
    -bash-4.2$ hostname
    client.home
    -bash-4.2$ id
    uid=1001(tim) gid=1001(tim) groups=1001(tim) 
    context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
    

    This directory should automount for user tim on client.home. Unfortunately, that does not seem to happen.

    [root@client ~]# su - tim
    -bash-4.2$ id
    uid=1001(tim) gid=1001(tim) groups=1001(tim) 
    context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
    -bash-4.2$ cd /home/tim
    -bash: cd: /home/tim: No such file or directory
    -bash-4.2$ ls /home
    vagrant
    

    Even though, I believe I have set up my auto.master file correctly.

    [root@client ~]# cat /etc/auto.master
    #
    # Sample auto.master file
    # This is a 'master' automounter map and it has the following format:
    # mount-point [map-type[,format]:]map [options]
    # For details of the format look at auto.master(5).
    #
    /misc   /etc/auto.misc
    #
    # NOTE: mounts done from a hosts map will be mounted with the
    #   "nosuid" and "nodev" options unless the "suid" and "dev"
    #   options are explicitly given.
    #
    /net    -hosts
    #
    # Include /etc/auto.master.d/*.autofs
    # The included files must conform to the format of this file.
    #
    +dir:/etc/auto.master.d
    #
    # Include central master map if it can be found using
    # nsswitch sources.
    #
    # Note that if there are entries for /net or /misc (as
    # above) in the included master map any keys that are the
    # same will not be seen as the first read key seen takes
    # precedence.
    #
    +auto.master
    
    /home   /etc/auto.home
    

    And the contents of my /etc/auto.home

    [root@client /]# cat /etc/auto.home 
    *   nfs4,rw     &:/home/&
    

    I would expect that I should be able to simply cd into the user's home directory. Instead, when autofs.service is running, I can't even create any files in /home.

    [root@client /]# systemctl is-active autofs
    active
    [root@client /]# touch /home/test
    touch: cannot touch ‘/home/test’: Permission denied
    [root@client home]# ll -d /home
    drwxr-xr-x. 2 root root 0 Sep 16 02:04 /home
    [root@client /]# systemctl stop autofs
    [root@client /]# systemctl is-active autofs
    inactive
    [root@client /]# touch /home/test
    [root@client /]# ls /home
    test  vagrant
    

    EDIT:

    I can manually mount the NFS shares. Also, I am pretty sure the strange permissions issues from before were due to the root_squash option I had set in the /etc/exports file.

    [root@client ~]# mount -t nfs4 -o rw server.home:/home/tim /mnt
    [root@client ~]# df -t nfs4
    Filesystem            1K-blocks    Used Available Use% Mounted on
    server.home:/home/tim  39269760 1192448  38077312   4% /mnt
    [root@client ~]# ll -d /mnt
    drwx------. 2 tim tim 86 Sep 16 18:51 /mnt
    
    • Thomas
      Thomas almost 7 years
      Can you mount the share manually on the client with mount server:/home/tim /mnt? Then you have to put your mount options nfs4,rw to /etc/auto.master as /home /etc/auto.home nfs4,rw. And you should specify a server in /etc/auto.home as * server:/home/&.
    • Timothy Pulliam
      Timothy Pulliam almost 7 years
      Yes, I can. See edit. I have also turned off my firewall.