$HOME, $HOME on the NFS
Or "Setting up $HOME on a NFS"
The goal is to have my users home directories on my home NAS automatically mounted whenever the login.
Install the support files
On RHEL systems, install autofs
and nfs-utils
.
Adjust users $HOME directory settings
Since I want to have both local (emergency) accounts as well as the NFS users, I left the local account $HOME directories alone and adjusted my users $HOME directory to be in the /home/nas/
directory.
If you're making new users, this is easy to do. If you're using pre-existing users, you'll need to update their information in your LDAP source - in my case they are currently defined only in the /etc/passwd
file, so I just adjusted the home directory filed. Originally it was this:
dan:x:1000:1000:Daniel Linder:/home/dan:/bin/bash
And I changed it to this:
dan:x:1000:1000:Daniel Linder:/home/nfs/dan:/bin/bash
Configure the auto.master file
Next we need to tell autofs
about the configuration changes we're making to auto.home
(next step). Just add these lines to the end of the /etc/auto.master
file:
# Added for autofs for $HOME
/home/nfs /etc/auto.home
This essentially tells the AutoFS system that "Anyone accessing something under /home/nfs
, see the /etc/auto.home
file for what to do."
Now map users to the NFS directories
Now create the /etc/auto.home
file with this line:
* -fstype=nfs4 nas:/volume1/homes/&
With this in place, this tells AutoFS "Anyone trying to get into a directory within /home/nfs/
, this will be an NFS4 mount (-fstype=nfs4
), and the NFS mount is nas:/volume1/homes/
." The wildcard (*
) refers to the the directory under /home/nfs/
and it is used in place of the &
at the end of the line.
For instance, if we have this all setup and we try to go to /home/nfs/dan
, the AutoFS system attempts to mount from the nas
server the NFS export named /volume1/homes/dan
, and mount it at /home/nfs/dan
.
This works as long as the NFS export has a directory under /volume1/homes/
to match the $HOME directory. You will need to make sure you keep your NFS export updated as you add and remove users from your environment.
Enable AutoFS service
Create the NFS mount directory, /home/nfs/
:
mkdir -p /home/nfs/
Finally start and enable the AutoFS service:
systemctl enable --now autofs.service
Test the connection
You can SSH into the system as a user who has their $HOME mapped to the /home/nfs
directory. Assuming their home directory mounts and the space in their $HOME directory is using the NFS share, you should be good.
admin@sno1:/etc# ssh dan@localhost
dan@localhost's password:
[dan@sno1 ~]$ df -h .
Filesystem Size Used Avail Use% Mounted on
nas:/volume1/homes/dan 17T 7.7T 9.0T 46% /home/nfs/dan
[dan@sno1 ~]$ exit
Connection to localhost closed.
Resources
I referenced these documents: