Step-by-step instruction to get benefits from NFS and Autofs.
We have two machines as always:
- srv2: has NFS server and a lot of disk space.(IP 10.0.30.2)
- srv1: has users and autofs daemon(IP 10.0.30.1)
Go to srv1 and make new user:
srv1#adduser user1
Get id:
srv1#id user1 uid=500(user1) gid=500(user1) groups=500(user1)
Open console on srv2 and make directory for home’s directoies:
srv2#mkdir /export_home
now make directory for specific user(user1):
srv2#mkdir /export_home/user1
and set proper owner:
srv2#chown 501 /export_home/user1
!!!where 501 owner ID which is got from srv1.
Next step is NFS configuration at srv2. Open /etc/exports and add new share point:
/export_home/user1 10.0.30.1(rw)
After changes is done reload services and put into boot:
/etc/init.d/nfs reload chkconfig --level 45 nfs on
srv2 is completely done. Back to srv1:
Add new line into /etc/auto.master:
/home /etc/auto.home
It’s pointed at new configuration file which will define mount point for /home directory. Put next line into it(/etc/auto.home):
user1 -rw,soft,intr 10.0.30.2:/export_home/user1
This line means mount NFS share /export_home/user1 from server 10.0.30.2 into local directory /home/user1. Restart autofs daemon to make changes take effect:
/etc/init.d/autofs restart
Now when you log in into system as user1 the NFS share from remote host will mount as your home directory. And will be unmount in timeout(300 seconds by default) after you have logged out.
Also you can put together this system with NIS so as to use common user database. As benefits you will get very flexible system and simplified user management.